19 #include "catalog/pg_attribute_d.h"
20 #include "catalog/pg_cast_d.h"
21 #include "catalog/pg_class_d.h"
22 #include "catalog/pg_default_acl_d.h"
34 const char *relationname,
46 const char *pnspname,
const char *prsname);
50 bool have_where,
bool force_escape,
51 const char *schemavar,
const char *namevar,
52 const char *altnamevar,
53 const char *visibilityrule,
54 bool *added_clause,
int maxparts);
80 "SELECT n.nspname as \"%s\",\n"
81 " p.proname AS \"%s\",\n"
82 " pg_catalog.format_type(p.prorettype, NULL) AS \"%s\",\n"
83 " CASE WHEN p.pronargs = 0\n"
84 " THEN CAST('*' AS pg_catalog.text)\n"
85 " ELSE pg_catalog.pg_get_function_arguments(p.oid)\n"
94 " pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"\n"
95 "FROM pg_catalog.pg_proc p\n"
96 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n"
97 "WHERE p.prokind = 'a'\n",
101 " pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"\n"
102 "FROM pg_catalog.pg_proc p\n"
103 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n"
104 "WHERE p.proisagg\n",
107 if (!showSystem && !pattern)
109 " AND n.nspname <> 'information_schema'\n");
112 "n.nspname",
"p.proname", NULL,
113 "pg_catalog.pg_function_is_visible(p.oid)",
127 myopt.
title =
_(
"List of aggregate functions");
146 static const bool translate_columns[] = {
false,
true,
false,
false};
152 pg_log_error(
"The server (version %s) does not support access methods.",
154 sverbuf,
sizeof(sverbuf)));
161 "SELECT amname AS \"%s\",\n"
163 " WHEN 'i' THEN '%s'"
164 " WHEN 't' THEN '%s'"
174 ",\n amhandler AS \"%s\",\n"
175 " pg_catalog.obj_description(oid, 'pg_am') AS \"%s\"",
181 "\nFROM pg_catalog.pg_am\n");
184 NULL,
"amname", NULL,
199 myopt.
title =
_(
"List of access methods");
224 "SELECT spcname AS \"%s\",\n"
225 " pg_catalog.pg_get_userbyid(spcowner) AS \"%s\",\n"
226 " pg_catalog.pg_tablespace_location(oid) AS \"%s\"",
236 ",\n spcoptions AS \"%s\""
237 ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_tablespace_size(oid)) AS \"%s\""
238 ",\n pg_catalog.shobj_description(oid, 'pg_tablespace') AS \"%s\"",
245 "\nFROM pg_catalog.pg_tablespace\n");
248 NULL,
"spcname", NULL,
263 myopt.
title =
_(
"List of tablespaces");
289 char **arg_patterns,
int num_arg_patterns,
292 bool showAggregate = strchr(functypes,
'a') != NULL;
293 bool showNormal = strchr(functypes,
'n') != NULL;
294 bool showProcedure = strchr(functypes,
'p') != NULL;
295 bool showTrigger = strchr(functypes,
't') != NULL;
296 bool showWindow = strchr(functypes,
'w') != NULL;
301 static const bool translate_columns[] = {
false,
false,
false,
false,
true,
true,
true,
false,
true,
false,
false,
false,
false};
304 static const bool translate_columns_pre_96[] = {
false,
false,
false,
false,
true,
true,
false,
true,
false,
false,
false,
false};
306 if (strlen(functypes) != strspn(functypes,
"anptwS+"))
316 pg_log_error(
"\\df does not take a \"%c\" option with server version %s",
319 sverbuf,
sizeof(sverbuf)));
323 if (!showAggregate && !showNormal && !showProcedure && !showTrigger && !showWindow)
325 showAggregate = showNormal = showTrigger = showWindow =
true;
327 showProcedure =
true;
333 "SELECT n.nspname as \"%s\",\n"
334 " p.proname as \"%s\",\n",
340 " pg_catalog.pg_get_function_result(p.oid) as \"%s\",\n"
341 " pg_catalog.pg_get_function_arguments(p.oid) as \"%s\",\n"
343 " WHEN 'a' THEN '%s'\n"
344 " WHEN 'w' THEN '%s'\n"
345 " WHEN 'p' THEN '%s'\n"
358 " pg_catalog.pg_get_function_result(p.oid) as \"%s\",\n"
359 " pg_catalog.pg_get_function_arguments(p.oid) as \"%s\",\n"
361 " WHEN p.proisagg THEN '%s'\n"
362 " WHEN p.proiswindow THEN '%s'\n"
363 " WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN '%s'\n"
379 " WHEN p.provolatile = 'i' THEN '%s'\n"
380 " WHEN p.provolatile = 's' THEN '%s'\n"
381 " WHEN p.provolatile = 'v' THEN '%s'\n"
390 " WHEN p.proparallel = 'r' THEN '%s'\n"
391 " WHEN p.proparallel = 's' THEN '%s'\n"
392 " WHEN p.proparallel = 'u' THEN '%s'\n"
399 ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\""
400 ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"",
408 ",\n l.lanname as \"%s\"",
411 ",\n CASE WHEN l.lanname IN ('internal', 'c') THEN p.prosrc END as \"%s\"",
414 ",\n pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"",
419 "\nFROM pg_catalog.pg_proc p"
420 "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n");
422 for (
int i = 0;
i < num_arg_patterns;
i++)
425 " LEFT JOIN pg_catalog.pg_type t%d ON t%d.oid = p.proargtypes[%d]\n"
426 " LEFT JOIN pg_catalog.pg_namespace nt%d ON nt%d.oid = t%d.typnamespace\n",
432 " LEFT JOIN pg_catalog.pg_language l ON l.oid = p.prolang\n");
437 if (showNormal && showAggregate && showProcedure && showTrigger && showWindow)
494 bool needs_or =
false;
512 "p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype\n");
535 "n.nspname",
"p.proname", NULL,
536 "pg_catalog.pg_function_is_visible(p.oid)",
540 for (
int i = 0;
i < num_arg_patterns;
i++)
542 if (strcmp(arg_patterns[
i],
"-") != 0)
554 snprintf(nspname,
sizeof(nspname),
"nt%d.nspname",
i);
557 "pg_catalog.format_type(t%d.oid, NULL)",
i);
559 "pg_catalog.pg_type_is_visible(t%d.oid)",
i);
574 if (!showSystem && !func_pattern)
576 " AND n.nspname <> 'information_schema'\n");
585 myopt.
title =
_(
"List of functions");
624 "SELECT n.nspname as \"%s\",\n"
625 " pg_catalog.format_type(t.oid, NULL) AS \"%s\",\n",
631 " t.typname AS \"%s\",\n"
632 " CASE WHEN t.typrelid != 0\n"
633 " THEN CAST('tuple' AS pg_catalog.text)\n"
634 " WHEN t.typlen < 0\n"
635 " THEN CAST('var' AS pg_catalog.text)\n"
636 " ELSE CAST(t.typlen AS pg_catalog.text)\n"
638 " pg_catalog.array_to_string(\n"
640 " SELECT e.enumlabel\n"
641 " FROM pg_catalog.pg_enum e\n"
642 " WHERE e.enumtypid = t.oid\n"
643 " ORDER BY e.enumsortorder\n"
647 " pg_catalog.pg_get_userbyid(t.typowner) AS \"%s\",\n",
657 " pg_catalog.obj_description(t.oid, 'pg_type') as \"%s\"\n",
661 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
669 " FROM pg_catalog.pg_class c "
670 "WHERE c.oid = t.typrelid))\n");
675 if (pattern == NULL || strstr(pattern,
"[]") == NULL)
676 appendPQExpBufferStr(&
buf,
" AND NOT EXISTS(SELECT 1 FROM pg_catalog.pg_type el WHERE el.oid = t.typelem AND el.typarray = t.oid)\n");
678 if (!showSystem && !pattern)
680 " AND n.nspname <> 'information_schema'\n");
685 "n.nspname",
"t.typname",
686 "pg_catalog.format_type(t.oid, NULL)",
687 "pg_catalog.pg_type_is_visible(t.oid)",
701 myopt.
title =
_(
"List of data types");
722 static const char *
const typename_map[] = {
728 "decimal",
"numeric",
729 "float",
"double precision",
736 "bool[]",
"boolean[]",
737 "decimal[]",
"numeric[]",
738 "float[]",
"double precision[]",
739 "float4[]",
"real[]",
740 "float8[]",
"double precision[]",
741 "int[]",
"integer[]",
742 "int2[]",
"smallint[]",
743 "int4[]",
"integer[]",
744 "int8[]",
"bigint[]",
745 "time[]",
"time without time zone[]",
746 "timetz[]",
"time with time zone[]",
747 "timestamp[]",
"timestamp without time zone[]",
748 "timestamptz[]",
"timestamp with time zone[]",
749 "varbit[]",
"bit varying[]",
750 "varchar[]",
"character varying[]",
756 for (
int i = 0; typename_map[
i] != NULL;
i += 2)
759 return typename_map[
i + 1];
771 char **arg_patterns,
int num_arg_patterns,
797 "SELECT n.nspname as \"%s\",\n"
798 " o.oprname AS \"%s\",\n"
799 " CASE WHEN o.oprkind='l' THEN NULL ELSE pg_catalog.format_type(o.oprleft, NULL) END AS \"%s\",\n"
800 " CASE WHEN o.oprkind='r' THEN NULL ELSE pg_catalog.format_type(o.oprright, NULL) END AS \"%s\",\n"
801 " pg_catalog.format_type(o.oprresult, NULL) AS \"%s\",\n",
810 " o.oprcode AS \"%s\",\n",
814 " coalesce(pg_catalog.obj_description(o.oid, 'pg_operator'),\n"
815 " pg_catalog.obj_description(o.oprcode, 'pg_proc')) AS \"%s\"\n"
816 "FROM pg_catalog.pg_operator o\n"
817 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = o.oprnamespace\n",
820 if (num_arg_patterns >= 2)
822 num_arg_patterns = 2;
824 " LEFT JOIN pg_catalog.pg_type t0 ON t0.oid = o.oprleft\n"
825 " LEFT JOIN pg_catalog.pg_namespace nt0 ON nt0.oid = t0.typnamespace\n"
826 " LEFT JOIN pg_catalog.pg_type t1 ON t1.oid = o.oprright\n"
827 " LEFT JOIN pg_catalog.pg_namespace nt1 ON nt1.oid = t1.typnamespace\n");
829 else if (num_arg_patterns == 1)
832 " LEFT JOIN pg_catalog.pg_type t0 ON t0.oid = o.oprright\n"
833 " LEFT JOIN pg_catalog.pg_namespace nt0 ON nt0.oid = t0.typnamespace\n");
836 if (!showSystem && !oper_pattern)
838 " AND n.nspname <> 'information_schema'\n");
841 !showSystem && !oper_pattern,
true,
842 "n.nspname",
"o.oprname", NULL,
843 "pg_catalog.pg_operator_is_visible(o.oid)",
847 if (num_arg_patterns == 1)
850 for (
int i = 0;
i < num_arg_patterns;
i++)
852 if (strcmp(arg_patterns[
i],
"-") != 0)
864 snprintf(nspname,
sizeof(nspname),
"nt%d.nspname",
i);
867 "pg_catalog.format_type(t%d.oid, NULL)",
i);
869 "pg_catalog.pg_type_is_visible(t%d.oid)",
i);
891 myopt.
title =
_(
"List of operators");
921 " d.datname as \"%s\",\n"
922 " pg_catalog.pg_get_userbyid(d.datdba) as \"%s\",\n"
923 " pg_catalog.pg_encoding_to_char(d.encoding) as \"%s\",\n",
929 " CASE d.datlocprovider WHEN 'b' THEN 'builtin' WHEN 'c' THEN 'libc' WHEN 'i' THEN 'icu' END AS \"%s\",\n",
933 " 'libc' AS \"%s\",\n",
936 " d.datcollate as \"%s\",\n"
937 " d.datctype as \"%s\",\n",
942 " d.datlocale as \"%s\",\n",
946 " d.daticulocale as \"%s\",\n",
950 " NULL as \"%s\",\n",
954 " d.daticurules as \"%s\",\n",
958 " NULL as \"%s\",\n",
964 ",\n CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT')\n"
965 " THEN pg_catalog.pg_size_pretty(pg_catalog.pg_database_size(d.datname))\n"
966 " ELSE 'No Access'\n"
968 ",\n t.spcname as \"%s\""
969 ",\n pg_catalog.shobj_description(d.oid, 'pg_database') as \"%s\"",
974 "\nFROM pg_catalog.pg_database d\n");
977 " JOIN pg_catalog.pg_tablespace t on d.dattablespace = t.oid\n");
982 NULL,
"d.datname", NULL, NULL,
996 myopt.
title =
_(
"List of databases");
1016 static const bool translate_columns[] = {
false,
false,
true,
false,
false,
false};
1024 "SELECT n.nspname as \"%s\",\n"
1025 " c.relname as \"%s\",\n"
1031 " WHEN " CppAsString2(RELKIND_FOREIGN_TABLE)
" THEN '%s'"
1032 " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE)
" THEN '%s'"
1053 ",\n pg_catalog.array_to_string(ARRAY(\n"
1054 " SELECT attname || E':\\n ' || pg_catalog.array_to_string(attacl, E'\\n ')\n"
1055 " FROM pg_catalog.pg_attribute a\n"
1056 " WHERE attrelid = c.oid AND NOT attisdropped AND attacl IS NOT NULL\n"
1057 " ), E'\\n') AS \"%s\"",
1062 ",\n pg_catalog.array_to_string(ARRAY(\n"
1064 " || CASE WHEN polcmd != '*' THEN\n"
1065 " E' (' || polcmd::pg_catalog.text || E'):'\n"
1068 " || CASE WHEN polqual IS NOT NULL THEN\n"
1069 " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n"
1072 " || CASE WHEN polwithcheck IS NOT NULL THEN\n"
1073 " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n"
1076 " || CASE WHEN polroles <> '{0}' THEN\n"
1077 " E'\\n to: ' || pg_catalog.array_to_string(\n"
1080 " FROM pg_catalog.pg_roles\n"
1081 " WHERE oid = ANY (polroles)\n"
1086 " FROM pg_catalog.pg_policy pol\n"
1087 " WHERE polrelid = c.oid), E'\\n')\n"
1093 ",\n pg_catalog.array_to_string(ARRAY(\n"
1095 " || CASE WHEN NOT polpermissive THEN\n"
1096 " E' (RESTRICTIVE)'\n"
1098 " || CASE WHEN polcmd != '*' THEN\n"
1099 " E' (' || polcmd::pg_catalog.text || E'):'\n"
1102 " || CASE WHEN polqual IS NOT NULL THEN\n"
1103 " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n"
1106 " || CASE WHEN polwithcheck IS NOT NULL THEN\n"
1107 " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n"
1110 " || CASE WHEN polroles <> '{0}' THEN\n"
1111 " E'\\n to: ' || pg_catalog.array_to_string(\n"
1114 " FROM pg_catalog.pg_roles\n"
1115 " WHERE oid = ANY (polroles)\n"
1120 " FROM pg_catalog.pg_policy pol\n"
1121 " WHERE polrelid = c.oid), E'\\n')\n"
1126 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
1127 "WHERE c.relkind IN ("
1135 if (!showSystem && !pattern)
1137 " AND n.nspname <> 'information_schema'\n");
1140 "n.nspname",
"c.relname", NULL,
1141 "pg_catalog.pg_table_is_visible(c.oid)",
1180 static const bool translate_columns[] = {
false,
false,
true,
false};
1185 "SELECT pg_catalog.pg_get_userbyid(d.defaclrole) AS \"%s\",\n"
1186 " n.nspname AS \"%s\",\n"
1187 " CASE d.defaclobjtype WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' END AS \"%s\",\n"
1199 DEFACLOBJ_NAMESPACE,
1206 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.defaclnamespace\n");
1211 "pg_catalog.pg_get_userbyid(d.defaclrole)",
1257 static const bool translate_columns[] = {
false,
false,
true,
false};
1262 "SELECT DISTINCT tt.nspname AS \"%s\", tt.name AS \"%s\", tt.object AS \"%s\", d.description AS \"%s\"\n"
1271 " SELECT pgc.oid as oid, pgc.tableoid AS tableoid,\n"
1272 " n.nspname as nspname,\n"
1273 " CAST(pgc.conname AS pg_catalog.text) as name,"
1274 " CAST('%s' AS pg_catalog.text) as object\n"
1275 " FROM pg_catalog.pg_constraint pgc\n"
1276 " JOIN pg_catalog.pg_class c "
1277 "ON c.oid = pgc.conrelid\n"
1278 " LEFT JOIN pg_catalog.pg_namespace n "
1279 " ON n.oid = c.relnamespace\n",
1282 if (!showSystem && !pattern)
1284 " AND n.nspname <> 'information_schema'\n");
1287 false,
"n.nspname",
"pgc.conname", NULL,
1288 "pg_catalog.pg_table_is_visible(c.oid)",
1295 " SELECT pgc.oid as oid, pgc.tableoid AS tableoid,\n"
1296 " n.nspname as nspname,\n"
1297 " CAST(pgc.conname AS pg_catalog.text) as name,"
1298 " CAST('%s' AS pg_catalog.text) as object\n"
1299 " FROM pg_catalog.pg_constraint pgc\n"
1300 " JOIN pg_catalog.pg_type t "
1301 "ON t.oid = pgc.contypid\n"
1302 " LEFT JOIN pg_catalog.pg_namespace n "
1303 " ON n.oid = t.typnamespace\n",
1306 if (!showSystem && !pattern)
1308 " AND n.nspname <> 'information_schema'\n");
1311 false,
"n.nspname",
"pgc.conname", NULL,
1312 "pg_catalog.pg_type_is_visible(t.oid)",
1319 " SELECT o.oid as oid, o.tableoid as tableoid,\n"
1320 " n.nspname as nspname,\n"
1321 " CAST(o.opcname AS pg_catalog.text) as name,\n"
1322 " CAST('%s' AS pg_catalog.text) as object\n"
1323 " FROM pg_catalog.pg_opclass o\n"
1324 " JOIN pg_catalog.pg_am am ON "
1325 "o.opcmethod = am.oid\n"
1326 " JOIN pg_catalog.pg_namespace n ON "
1327 "n.oid = o.opcnamespace\n",
1330 if (!showSystem && !pattern)
1332 " AND n.nspname <> 'information_schema'\n");
1335 "n.nspname",
"o.opcname", NULL,
1336 "pg_catalog.pg_opclass_is_visible(o.oid)",
1343 " SELECT opf.oid as oid, opf.tableoid as tableoid,\n"
1344 " n.nspname as nspname,\n"
1345 " CAST(opf.opfname AS pg_catalog.text) AS name,\n"
1346 " CAST('%s' AS pg_catalog.text) as object\n"
1347 " FROM pg_catalog.pg_opfamily opf\n"
1348 " JOIN pg_catalog.pg_am am "
1349 "ON opf.opfmethod = am.oid\n"
1350 " JOIN pg_catalog.pg_namespace n "
1351 "ON opf.opfnamespace = n.oid\n",
1354 if (!showSystem && !pattern)
1356 " AND n.nspname <> 'information_schema'\n");
1359 "n.nspname",
"opf.opfname", NULL,
1360 "pg_catalog.pg_opfamily_is_visible(opf.oid)",
1367 " SELECT r.oid as oid, r.tableoid as tableoid,\n"
1368 " n.nspname as nspname,\n"
1369 " CAST(r.rulename AS pg_catalog.text) as name,"
1370 " CAST('%s' AS pg_catalog.text) as object\n"
1371 " FROM pg_catalog.pg_rewrite r\n"
1372 " JOIN pg_catalog.pg_class c ON c.oid = r.ev_class\n"
1373 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
1374 " WHERE r.rulename != '_RETURN'\n",
1377 if (!showSystem && !pattern)
1379 " AND n.nspname <> 'information_schema'\n");
1382 "n.nspname",
"r.rulename", NULL,
1383 "pg_catalog.pg_table_is_visible(c.oid)",
1390 " SELECT t.oid as oid, t.tableoid as tableoid,\n"
1391 " n.nspname as nspname,\n"
1392 " CAST(t.tgname AS pg_catalog.text) as name,"
1393 " CAST('%s' AS pg_catalog.text) as object\n"
1394 " FROM pg_catalog.pg_trigger t\n"
1395 " JOIN pg_catalog.pg_class c ON c.oid = t.tgrelid\n"
1396 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n",
1399 if (!showSystem && !pattern)
1401 " AND n.nspname <> 'information_schema'\n");
1404 "n.nspname",
"t.tgname", NULL,
1405 "pg_catalog.pg_table_is_visible(c.oid)",
1411 " JOIN pg_catalog.pg_description d ON (tt.oid = d.objoid AND tt.tableoid = d.classoid AND d.objsubid = 0)\n");
1420 myopt.
title =
_(
"Object descriptions");
1457 "FROM pg_catalog.pg_class c\n"
1458 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n");
1460 if (!showSystem && !pattern)
1462 " AND n.nspname <> 'information_schema'\n");
1465 "n.nspname",
"c.relname", NULL,
1466 "pg_catalog.pg_table_is_visible(c.oid)",
1485 pg_log_error(
"Did not find any relation named \"%s\".",
1497 const char *nspname;
1529 const char *relationname,
1533 bool retval =
false;
1538 bool printTableInitialized =
false;
1540 char *view_def = NULL;
1545 int attname_col = -1,
1548 attnotnull_col = -1,
1550 attidentity_col = -1,
1551 attgenerated_col = -1,
1552 isindexkey_col = -1,
1555 attstorage_col = -1,
1556 attcompression_col = -1,
1557 attstattarget_col = -1,
1568 bool forcerowsecurity;
1574 char relpersistence;
1578 bool show_column_details =
false;
1592 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1593 "c.relhastriggers, c.relrowsecurity, c.relforcerowsecurity, "
1594 "false AS relhasoids, c.relispartition, %s, c.reltablespace, "
1595 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
1596 "c.relpersistence, c.relreplident, am.amname\n"
1597 "FROM pg_catalog.pg_class c\n "
1598 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1599 "LEFT JOIN pg_catalog.pg_am am ON (c.relam = am.oid)\n"
1600 "WHERE c.oid = '%s';",
1602 "pg_catalog.array_to_string(c.reloptions || "
1603 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1610 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1611 "c.relhastriggers, c.relrowsecurity, c.relforcerowsecurity, "
1612 "c.relhasoids, c.relispartition, %s, c.reltablespace, "
1613 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
1614 "c.relpersistence, c.relreplident\n"
1615 "FROM pg_catalog.pg_class c\n "
1616 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1617 "WHERE c.oid = '%s';",
1619 "pg_catalog.array_to_string(c.reloptions || "
1620 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1627 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1628 "c.relhastriggers, c.relrowsecurity, c.relforcerowsecurity, "
1629 "c.relhasoids, false as relispartition, %s, c.reltablespace, "
1630 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
1631 "c.relpersistence, c.relreplident\n"
1632 "FROM pg_catalog.pg_class c\n "
1633 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1634 "WHERE c.oid = '%s';",
1636 "pg_catalog.array_to_string(c.reloptions || "
1637 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1644 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1645 "c.relhastriggers, false, false, c.relhasoids, "
1646 "false as relispartition, %s, c.reltablespace, "
1647 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
1648 "c.relpersistence, c.relreplident\n"
1649 "FROM pg_catalog.pg_class c\n "
1650 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1651 "WHERE c.oid = '%s';",
1653 "pg_catalog.array_to_string(c.reloptions || "
1654 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1661 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1662 "c.relhastriggers, false, false, c.relhasoids, "
1663 "false as relispartition, %s, c.reltablespace, "
1664 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
1665 "c.relpersistence\n"
1666 "FROM pg_catalog.pg_class c\n "
1667 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1668 "WHERE c.oid = '%s';",
1670 "pg_catalog.array_to_string(c.reloptions || "
1671 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1684 pg_log_error(
"Did not find any relation with OID %s.", oid);
1690 tableinfo.hasindex = strcmp(
PQgetvalue(
res, 0, 2),
"t") == 0;
1691 tableinfo.hasrules = strcmp(
PQgetvalue(
res, 0, 3),
"t") == 0;
1692 tableinfo.hastriggers = strcmp(
PQgetvalue(
res, 0, 4),
"t") == 0;
1693 tableinfo.rowsecurity = strcmp(
PQgetvalue(
res, 0, 5),
"t") == 0;
1694 tableinfo.forcerowsecurity = strcmp(
PQgetvalue(
res, 0, 6),
"t") == 0;
1695 tableinfo.hasoids = strcmp(
PQgetvalue(
res, 0, 7),
"t") == 0;
1696 tableinfo.ispartition = strcmp(
PQgetvalue(
res, 0, 8),
"t") == 0;
1699 tableinfo.reloftype = (strcmp(
PQgetvalue(
res, 0, 11),
"") != 0) ?
1708 tableinfo.relam = NULL;
1715 if (tableinfo.relkind == RELKIND_SEQUENCE)
1719 char *footers[2] = {NULL, NULL};
1724 "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n"
1725 " seqstart AS \"%s\",\n"
1726 " seqmin AS \"%s\",\n"
1727 " seqmax AS \"%s\",\n"
1728 " seqincrement AS \"%s\",\n"
1729 " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n"
1730 " seqcache AS \"%s\"\n",
1741 "FROM pg_catalog.pg_sequence\n"
1742 "WHERE seqrelid = '%s';",
1748 "SELECT 'bigint' AS \"%s\",\n"
1749 " start_value AS \"%s\",\n"
1750 " min_value AS \"%s\",\n"
1751 " max_value AS \"%s\",\n"
1752 " increment_by AS \"%s\",\n"
1753 " CASE WHEN is_cycled THEN '%s' ELSE '%s' END AS \"%s\",\n"
1754 " cache_value AS \"%s\"\n",
1775 "\n pg_catalog.quote_ident(relname) || '.' ||"
1776 "\n pg_catalog.quote_ident(attname),"
1778 "\nFROM pg_catalog.pg_class c"
1779 "\nINNER JOIN pg_catalog.pg_depend d ON c.oid=d.refobjid"
1780 "\nINNER JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace"
1781 "\nINNER JOIN pg_catalog.pg_attribute a ON ("
1782 "\n a.attrelid=c.oid AND"
1783 "\n a.attnum=d.refobjsubid)"
1784 "\nWHERE d.classid='pg_catalog.pg_class'::pg_catalog.regclass"
1785 "\n AND d.refclassid='pg_catalog.pg_class'::pg_catalog.regclass"
1786 "\n AND d.objid='%s'"
1787 "\n AND d.deptype IN ('a', 'i')",
1804 footers[0] =
psprintf(
_(
"Owned by: %s"),
1808 footers[0] =
psprintf(
_(
"Sequence for identity column: %s"),
1815 if (tableinfo.relpersistence ==
'u')
1817 schemaname, relationname);
1820 schemaname, relationname);
1836 if (tableinfo.relkind == RELKIND_RELATION ||
1837 tableinfo.relkind == RELKIND_VIEW ||
1838 tableinfo.relkind == RELKIND_MATVIEW ||
1839 tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
1840 tableinfo.relkind == RELKIND_COMPOSITE_TYPE ||
1841 tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
1842 show_column_details =
true;
1854 attname_col = cols++;
1856 atttype_col = cols++;
1858 if (show_column_details)
1862 ",\n (SELECT pg_catalog.pg_get_expr(d.adbin, d.adrelid, true)"
1863 "\n FROM pg_catalog.pg_attrdef d"
1864 "\n WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef)"
1865 ",\n a.attnotnull");
1866 attrdef_col = cols++;
1867 attnotnull_col = cols++;
1869 " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation");
1870 attcoll_col = cols++;
1875 attidentity_col = cols++;
1880 attgenerated_col = cols++;
1882 if (tableinfo.relkind == RELKIND_INDEX ||
1883 tableinfo.relkind == RELKIND_PARTITIONED_INDEX)
1887 appendPQExpBuffer(&
buf,
",\n CASE WHEN a.attnum <= (SELECT i.indnkeyatts FROM pg_catalog.pg_index i WHERE i.indexrelid = '%s') THEN '%s' ELSE '%s' END AS is_key",
1891 isindexkey_col = cols++;
1894 indexdef_col = cols++;
1897 if (tableinfo.relkind == RELKIND_FOREIGN_TABLE)
1900 " '(' || pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(option_name) || ' ' || pg_catalog.quote_literal(option_value) FROM "
1901 " pg_catalog.pg_options_to_table(attfdwoptions)), ', ') || ')' END AS attfdwoptions");
1902 fdwopts_col = cols++;
1907 attstorage_col = cols++;
1912 (tableinfo.relkind == RELKIND_RELATION ||
1913 tableinfo.relkind == RELKIND_PARTITIONED_TABLE ||
1914 tableinfo.relkind == RELKIND_MATVIEW))
1917 attcompression_col = cols++;
1921 if (tableinfo.relkind == RELKIND_RELATION ||
1922 tableinfo.relkind == RELKIND_INDEX ||
1923 tableinfo.relkind == RELKIND_PARTITIONED_INDEX ||
1924 tableinfo.relkind == RELKIND_MATVIEW ||
1925 tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
1926 tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
1928 appendPQExpBufferStr(&
buf,
",\n CASE WHEN a.attstattarget=-1 THEN NULL ELSE a.attstattarget END AS attstattarget");
1929 attstattarget_col = cols++;
1936 if (tableinfo.relkind == RELKIND_RELATION ||
1937 tableinfo.relkind == RELKIND_VIEW ||
1938 tableinfo.relkind == RELKIND_MATVIEW ||
1939 tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
1940 tableinfo.relkind == RELKIND_COMPOSITE_TYPE ||
1941 tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
1944 attdescr_col = cols++;
1949 appendPQExpBuffer(&
buf,
"\nWHERE a.attrelid = '%s' AND a.attnum > 0 AND NOT a.attisdropped", oid);
1958 switch (tableinfo.relkind)
1960 case RELKIND_RELATION:
1961 if (tableinfo.relpersistence ==
'u')
1963 schemaname, relationname);
1966 schemaname, relationname);
1970 schemaname, relationname);
1972 case RELKIND_MATVIEW:
1973 if (tableinfo.relpersistence ==
'u')
1975 schemaname, relationname);
1978 schemaname, relationname);
1981 if (tableinfo.relpersistence ==
'u')
1983 schemaname, relationname);
1986 schemaname, relationname);
1988 case RELKIND_PARTITIONED_INDEX:
1989 if (tableinfo.relpersistence ==
'u')
1991 schemaname, relationname);
1994 schemaname, relationname);
1996 case RELKIND_TOASTVALUE:
1998 schemaname, relationname);
2000 case RELKIND_COMPOSITE_TYPE:
2002 schemaname, relationname);
2004 case RELKIND_FOREIGN_TABLE:
2006 schemaname, relationname);
2008 case RELKIND_PARTITIONED_TABLE:
2009 if (tableinfo.relpersistence ==
'u')
2011 schemaname, relationname);
2014 schemaname, relationname);
2019 tableinfo.relkind, schemaname, relationname);
2027 if (show_column_details)
2033 if (isindexkey_col >= 0)
2035 if (indexdef_col >= 0)
2037 if (fdwopts_col >= 0)
2039 if (attstorage_col >= 0)
2041 if (attcompression_col >= 0)
2043 if (attstattarget_col >= 0)
2045 if (attdescr_col >= 0)
2051 printTableInitialized =
true;
2053 for (
i = 0;
i < cols;
i++)
2057 for (
i = 0;
i < numrows;
i++)
2066 if (show_column_details)
2071 bool mustfree =
false;
2076 strcmp(
PQgetvalue(
res,
i, attnotnull_col),
"t") == 0 ?
"not null" :
"",
2082 if (identity[0] == ATTRIBUTE_IDENTITY_ALWAYS)
2083 default_str =
"generated always as identity";
2084 else if (identity[0] == ATTRIBUTE_IDENTITY_BY_DEFAULT)
2085 default_str =
"generated by default as identity";
2086 else if (generated[0] == ATTRIBUTE_GENERATED_STORED)
2088 default_str =
psprintf(
"generated always as (%s) stored",
2099 if (isindexkey_col >= 0)
2101 if (indexdef_col >= 0)
2105 if (fdwopts_col >= 0)
2109 if (attstorage_col >= 0)
2116 (
storage[0] ==
'x' ?
"extended" :
2117 (
storage[0] ==
'e' ?
"external" :
2123 if (attcompression_col >= 0)
2129 (compression[0] ==
'l' ?
"lz4" :
2130 (compression[0] ==
'\0' ?
"" :
2136 if (attstattarget_col >= 0)
2141 if (attdescr_col >= 0)
2148 if (tableinfo.ispartition)
2154 "SELECT inhparent::pg_catalog.regclass,\n"
2155 " pg_catalog.pg_get_expr(c.relpartbound, c.oid),\n ");
2159 "false as inhdetachpending");
2164 ",\n pg_catalog.pg_get_partition_constraintdef(c.oid)");
2166 "\nFROM pg_catalog.pg_class c"
2167 " JOIN pg_catalog.pg_inherits i"
2168 " ON c.oid = inhrelid"
2169 "\nWHERE c.oid = '%s';", oid);
2176 char *parent_name =
PQgetvalue(result, 0, 0);
2182 strcmp(detached,
"t") == 0 ?
" DETACH PENDING" :
"");
2187 char *partconstraintdef = NULL;
2190 partconstraintdef =
PQgetvalue(result, 0, 3);
2192 if (partconstraintdef == NULL || partconstraintdef[0] ==
'\0')
2203 if (tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
2209 "SELECT pg_catalog.pg_get_partkeydef('%s'::pg_catalog.oid);",
2225 if (tableinfo.relkind == RELKIND_TOASTVALUE)
2231 "SELECT n.nspname, c.relname\n"
2232 "FROM pg_catalog.pg_class c"
2233 " JOIN pg_catalog.pg_namespace n"
2234 " ON n.oid = c.relnamespace\n"
2235 "WHERE reltoastrelid = '%s';", oid);
2252 if (tableinfo.relkind == RELKIND_INDEX ||
2253 tableinfo.relkind == RELKIND_PARTITIONED_INDEX)
2259 "SELECT i.indisunique, i.indisprimary, i.indisclustered, "
2261 " (NOT i.indimmediate) AND "
2262 "EXISTS (SELECT 1 FROM pg_catalog.pg_constraint "
2263 "WHERE conrelid = i.indrelid AND "
2264 "conindid = i.indexrelid AND "
2265 "contype IN ('p','u','x') AND "
2266 "condeferrable) AS condeferrable,\n"
2267 " (NOT i.indimmediate) AND "
2268 "EXISTS (SELECT 1 FROM pg_catalog.pg_constraint "
2269 "WHERE conrelid = i.indrelid AND "
2270 "conindid = i.indexrelid AND "
2271 "contype IN ('p','u','x') AND "
2272 "condeferred) AS condeferred,\n");
2285 "pg_catalog.pg_get_expr(i.indpred, i.indrelid, true)\n"
2286 "FROM pg_catalog.pg_index i, pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_am a\n"
2287 "WHERE i.indexrelid = c.oid AND c.oid = '%s' AND c.relam = a.oid\n"
2288 "AND i.indrelid = c2.oid;",
2301 char *indisunique =
PQgetvalue(result, 0, 0);
2302 char *indisprimary =
PQgetvalue(result, 0, 1);
2303 char *indisclustered =
PQgetvalue(result, 0, 2);
2307 char *indisreplident =
PQgetvalue(result, 0, 6);
2308 char *indnullsnotdistinct =
PQgetvalue(result, 0, 7);
2313 if (strcmp(indisprimary,
"t") == 0)
2315 else if (strcmp(indisunique,
"t") == 0)
2318 if (strcmp(indnullsnotdistinct,
"t") == 0)
2328 schemaname, indtable);
2330 if (strlen(indpred))
2333 if (strcmp(indisclustered,
"t") == 0)
2336 if (strcmp(indisvalid,
"t") != 0)
2339 if (strcmp(deferrable,
"t") == 0)
2342 if (strcmp(deferred,
"t") == 0)
2345 if (strcmp(indisreplident,
"t") == 0)
2353 if (tableinfo.relkind == RELKIND_INDEX)
2355 tableinfo.tablespace,
true);
2361 else if (tableinfo.relkind == RELKIND_RELATION ||
2362 tableinfo.relkind == RELKIND_MATVIEW ||
2363 tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
2364 tableinfo.relkind == RELKIND_PARTITIONED_TABLE ||
2365 tableinfo.relkind == RELKIND_PARTITIONED_INDEX ||
2366 tableinfo.relkind == RELKIND_TOASTVALUE)
2373 if (tableinfo.hasindex)
2376 "SELECT c2.relname, i.indisprimary, i.indisunique, "
2377 "i.indisclustered, i.indisvalid, "
2378 "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n "
2379 "pg_catalog.pg_get_constraintdef(con.oid, true), "
2380 "contype, condeferrable, condeferred");
2391 "\nFROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i\n"
2392 " LEFT JOIN pg_catalog.pg_constraint con ON (conrelid = i.indrelid AND conindid = i.indexrelid AND contype IN ('p','u','x'))\n"
2393 "WHERE c.oid = '%s' AND c.oid = i.indrelid AND i.indexrelid = c2.oid\n"
2394 "ORDER BY i.indisprimary DESC, c2.relname;",
2405 for (
i = 0;
i < tuples;
i++)
2423 const char *indexdef;
2424 const char *usingpos;
2429 else if (strcmp(
PQgetvalue(result,
i, 2),
"t") == 0)
2439 usingpos = strstr(indexdef,
" USING ");
2441 indexdef = usingpos + 7;
2474 if (tableinfo.checks)
2477 "SELECT r.conname, "
2478 "pg_catalog.pg_get_constraintdef(r.oid, true)\n"
2479 "FROM pg_catalog.pg_constraint r\n"
2480 "WHERE r.conrelid = '%s' AND r.contype = 'c'\n"
2492 for (
i = 0;
i < tuples;
i++)
2510 if (tableinfo.hastriggers ||
2511 tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
2514 (tableinfo.ispartition || tableinfo.relkind == RELKIND_PARTITIONED_TABLE))
2521 "SELECT conrelid = '%s'::pg_catalog.regclass AS sametable,\n"
2523 " pg_catalog.pg_get_constraintdef(oid, true) AS condef,\n"
2524 " conrelid::pg_catalog.regclass AS ontable\n"
2525 " FROM pg_catalog.pg_constraint,\n"
2526 " pg_catalog.pg_partition_ancestors('%s')\n"
2527 " WHERE conrelid = relid AND contype = 'f' AND conparentid = 0\n"
2528 "ORDER BY sametable DESC, conname;",
2534 "SELECT true as sametable, conname,\n"
2535 " pg_catalog.pg_get_constraintdef(r.oid, true) as condef,\n"
2536 " conrelid::pg_catalog.regclass AS ontable\n"
2537 "FROM pg_catalog.pg_constraint r\n"
2538 "WHERE r.conrelid = '%s' AND r.contype = 'f'\n",
2554 int i_sametable =
PQfnumber(result,
"sametable"),
2555 i_conname =
PQfnumber(result,
"conname"),
2557 i_ontable =
PQfnumber(result,
"ontable");
2560 for (
i = 0;
i < tuples;
i++)
2567 if (strcmp(
PQgetvalue(result,
i, i_sametable),
"f") == 0)
2584 if (tableinfo.hastriggers ||
2585 tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
2590 "SELECT conname, conrelid::pg_catalog.regclass AS ontable,\n"
2591 " pg_catalog.pg_get_constraintdef(oid, true) AS condef\n"
2592 " FROM pg_catalog.pg_constraint c\n"
2593 " WHERE confrelid IN (SELECT pg_catalog.pg_partition_ancestors('%s')\n"
2594 " UNION ALL VALUES ('%s'::pg_catalog.regclass))\n"
2595 " AND contype = 'f' AND conparentid = 0\n"
2596 "ORDER BY conname;",
2602 "SELECT conname, conrelid::pg_catalog.regclass AS ontable,\n"
2603 " pg_catalog.pg_get_constraintdef(oid, true) AS condef\n"
2604 " FROM pg_catalog.pg_constraint\n"
2605 " WHERE confrelid = %s AND contype = 'f'\n"
2606 "ORDER BY conname;",
2618 int i_conname =
PQfnumber(result,
"conname"),
2619 i_ontable =
PQfnumber(result,
"ontable"),
2623 for (
i = 0;
i < tuples;
i++)
2642 " pol.polpermissive,\n");
2645 " 't' as polpermissive,\n");
2647 " CASE WHEN pol.polroles = '{0}' THEN NULL ELSE pg_catalog.array_to_string(array(select rolname from pg_catalog.pg_roles where oid = any (pol.polroles) order by 1),',') END,\n"
2648 " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n"
2649 " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n"
2650 " CASE pol.polcmd\n"
2651 " WHEN 'r' THEN 'SELECT'\n"
2652 " WHEN 'a' THEN 'INSERT'\n"
2653 " WHEN 'w' THEN 'UPDATE'\n"
2654 " WHEN 'd' THEN 'DELETE'\n"
2656 "FROM pg_catalog.pg_policy pol\n"
2657 "WHERE pol.polrelid = '%s' ORDER BY 1;",
2671 if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0)
2674 if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0)
2677 if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0)
2680 if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0)
2683 if (!tableinfo.rowsecurity && tuples > 0)
2687 for (
i = 0;
i < tuples;
i++)
2723 "stxrelid::pg_catalog.regclass, "
2724 "stxnamespace::pg_catalog.regnamespace::pg_catalog.text AS nsp, "
2726 "pg_catalog.pg_get_statisticsobjdef_columns(oid) AS columns,\n"
2727 " 'd' = any(stxkind) AS ndist_enabled,\n"
2728 " 'f' = any(stxkind) AS deps_enabled,\n"
2729 " 'm' = any(stxkind) AS mcv_enabled,\n"
2731 "FROM pg_catalog.pg_statistic_ext\n"
2732 "WHERE stxrelid = '%s'\n"
2733 "ORDER BY nsp, stxname;",
2746 for (
i = 0;
i < tuples;
i++)
2748 bool gotone =
false;
2750 bool has_dependencies;
2755 has_ndistinct = (strcmp(
PQgetvalue(result,
i, 5),
"t") == 0);
2756 has_dependencies = (strcmp(
PQgetvalue(result,
i, 6),
"t") == 0);
2757 has_mcv = (strcmp(
PQgetvalue(result,
i, 7),
"t") == 0);
2774 has_all = (has_ndistinct && has_dependencies && has_mcv);
2775 has_some = (has_ndistinct || has_dependencies || has_mcv);
2777 if (has_some && !has_all)
2788 if (has_dependencies)
2821 "stxrelid::pg_catalog.regclass, "
2822 "stxnamespace::pg_catalog.regnamespace AS nsp, "
2824 " (SELECT pg_catalog.string_agg(pg_catalog.quote_ident(attname),', ')\n"
2825 " FROM pg_catalog.unnest(stxkeys) s(attnum)\n"
2826 " JOIN pg_catalog.pg_attribute a ON (stxrelid = a.attrelid AND\n"
2827 " a.attnum = s.attnum AND NOT attisdropped)) AS columns,\n"
2828 " 'd' = any(stxkind) AS ndist_enabled,\n"
2829 " 'f' = any(stxkind) AS deps_enabled,\n"
2830 " 'm' = any(stxkind) AS mcv_enabled,\n");
2837 "WHERE stxrelid = '%s'\n"
2851 for (
i = 0;
i < tuples;
i++)
2853 bool gotone =
false;
2896 if (tableinfo.hasrules && tableinfo.relkind != RELKIND_MATVIEW)
2899 "SELECT r.rulename, trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true)), "
2901 "FROM pg_catalog.pg_rewrite r\n"
2902 "WHERE r.ev_class = '%s' ORDER BY 1;",
2915 for (category = 0; category < 4; category++)
2917 have_heading =
false;
2919 for (
i = 0;
i < tuples;
i++)
2921 const char *ruledef;
2922 bool list_rule =
false;
2964 have_heading =
true;
2987 "FROM pg_catalog.pg_publication p\n"
2988 " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n"
2989 " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n"
2990 "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n"
2993 " , pg_get_expr(pr.prqual, c.oid)\n"
2994 " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n"
2995 " (SELECT string_agg(attname, ', ')\n"
2996 " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n"
2997 " pg_catalog.pg_attribute\n"
2998 " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n"
3000 "FROM pg_catalog.pg_publication p\n"
3001 " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n"
3002 " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n"
3003 "WHERE pr.prrelid = '%s'\n"
3008 "FROM pg_catalog.pg_publication p\n"
3009 "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n"
3011 oid, oid, oid, oid);
3019 "FROM pg_catalog.pg_publication p\n"
3020 "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n"
3021 "WHERE pr.prrelid = '%s'\n"
3026 "FROM pg_catalog.pg_publication p\n"
3027 "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n"
3042 for (
i = 0;
i < tuples;
i++)
3064 if ((tableinfo.relkind == RELKIND_VIEW ||
3065 tableinfo.relkind == RELKIND_MATVIEW) &&
verbose)
3070 "SELECT pg_catalog.pg_get_viewdef('%s'::pg_catalog.oid, true);",
3091 if (tableinfo.hasrules)
3094 "SELECT r.rulename, trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true))\n"
3095 "FROM pg_catalog.pg_rewrite r\n"
3096 "WHERE r.ev_class = '%s' AND r.rulename != '_RETURN' ORDER BY 1;",
3107 const char *ruledef;
3125 if (tableinfo.hastriggers)
3132 "pg_catalog.pg_get_triggerdef(t.oid, true), "
3133 "t.tgenabled, t.tgisinternal,\n");
3151 " CASE WHEN t.tgparentid != 0 THEN\n"
3152 " (SELECT u.tgrelid::pg_catalog.regclass\n"
3153 " FROM pg_catalog.pg_trigger AS u,\n"
3154 " pg_catalog.pg_partition_ancestors(t.tgrelid) WITH ORDINALITY AS a(relid, depth)\n"
3155 " WHERE u.tgname = t.tgname AND u.tgrelid = a.relid\n"
3156 " AND u.tgparentid = 0\n"
3157 " ORDER BY a.depth LIMIT 1)\n"
3158 " END AS parent\n");
3163 "FROM pg_catalog.pg_trigger t\n"
3164 "WHERE t.tgrelid = '%s' AND ",
3176 " OR EXISTS (SELECT 1 FROM pg_catalog.pg_depend WHERE objid = t.oid \n"
3177 " AND refclassid = 'pg_catalog.pg_trigger'::pg_catalog.regclass))");
3199 for (category = 0; category <= 4; category++)
3201 have_heading =
false;
3202 for (
i = 0;
i < tuples;
i++)
3206 const char *usingpos;
3207 const char *tgenabled;
3208 const char *tgisinternal;
3215 list_trigger =
false;
3219 if (*tgenabled ==
'O' || *tgenabled ==
't')
3220 list_trigger =
true;
3223 if ((*tgenabled ==
'D' || *tgenabled ==
'f') &&
3224 *tgisinternal ==
'f')
3225 list_trigger =
true;
3228 if ((*tgenabled ==
'D' || *tgenabled ==
'f') &&
3229 *tgisinternal ==
't')
3230 list_trigger =
true;
3233 if (*tgenabled ==
'A')
3234 list_trigger =
true;
3237 if (*tgenabled ==
'R')
3238 list_trigger =
true;
3241 if (list_trigger ==
false)
3245 if (have_heading ==
false)
3266 have_heading =
true;
3271 usingpos = strstr(tgdef,
" TRIGGER ");
3273 tgdef = usingpos + 9;
3292 if (tableinfo.relkind == RELKIND_RELATION ||
3293 tableinfo.relkind == RELKIND_MATVIEW ||
3294 tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
3295 tableinfo.relkind == RELKIND_PARTITIONED_TABLE ||
3296 tableinfo.relkind == RELKIND_PARTITIONED_INDEX ||
3297 tableinfo.relkind == RELKIND_TOASTVALUE)
3299 bool is_partitioned;
3304 is_partitioned = (tableinfo.relkind == RELKIND_PARTITIONED_TABLE ||
3305 tableinfo.relkind == RELKIND_PARTITIONED_INDEX);
3308 if (tableinfo.relkind == RELKIND_FOREIGN_TABLE)
3314 "SELECT s.srvname,\n"
3315 " pg_catalog.array_to_string(ARRAY(\n"
3316 " SELECT pg_catalog.quote_ident(option_name)"
3317 " || ' ' || pg_catalog.quote_literal(option_value)\n"
3318 " FROM pg_catalog.pg_options_to_table(ftoptions)), ', ')\n"
3319 "FROM pg_catalog.pg_foreign_table f,\n"
3320 " pg_catalog.pg_foreign_server s\n"
3321 "WHERE f.ftrelid = '%s' AND s.oid = f.ftserver;",
3339 if (ftoptions && ftoptions[0] !=
'\0')
3349 "SELECT c.oid::pg_catalog.regclass\n"
3350 "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n"
3351 "WHERE c.oid = i.inhparent AND i.inhrelid = '%s'\n"
3352 " AND c.relkind != " CppAsString2(RELKIND_PARTITIONED_TABLE)
3353 " AND c.relkind != " CppAsString2(RELKIND_PARTITIONED_INDEX)
3354 "\nORDER BY inhseqno;",
3362 const char *s =
_(
"Inherits");
3367 for (
i = 0;
i < tuples;
i++)
3387 "SELECT c.oid::pg_catalog.regclass, c.relkind,"
3388 " inhdetachpending,"
3389 " pg_catalog.pg_get_expr(c.relpartbound, c.oid)\n"
3390 "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n"
3391 "WHERE c.oid = i.inhrelid AND i.inhparent = '%s'\n"
3392 "ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT',"
3393 " c.oid::pg_catalog.regclass::pg_catalog.text;",
3397 "SELECT c.oid::pg_catalog.regclass, c.relkind,"
3398 " false AS inhdetachpending,"
3399 " pg_catalog.pg_get_expr(c.relpartbound, c.oid)\n"
3400 "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n"
3401 "WHERE c.oid = i.inhrelid AND i.inhparent = '%s'\n"
3402 "ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT',"
3403 " c.oid::pg_catalog.regclass::pg_catalog.text;",
3407 "SELECT c.oid::pg_catalog.regclass, c.relkind,"
3408 " false AS inhdetachpending, NULL\n"
3409 "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n"
3410 "WHERE c.oid = i.inhrelid AND i.inhparent = '%s'\n"
3411 "ORDER BY c.oid::pg_catalog.regclass::pg_catalog.text;",
3425 if (is_partitioned && tuples == 0)
3445 const char *ct = is_partitioned ?
_(
"Partitions") :
_(
"Child tables");
3448 for (
i = 0;
i < tuples;
i++)
3460 if (child_relkind == RELKIND_PARTITIONED_TABLE ||
3461 child_relkind == RELKIND_PARTITIONED_INDEX)
3463 else if (child_relkind == RELKIND_FOREIGN_TABLE)
3476 if (tableinfo.reloftype)
3483 (tableinfo.relkind == RELKIND_RELATION ||
3484 tableinfo.relkind == RELKIND_MATVIEW) &&
3490 tableinfo.relreplident !=
'i' &&
3491 ((strcmp(schemaname,
"pg_catalog") != 0 && tableinfo.relreplident !=
'd') ||
3492 (strcmp(schemaname,
"pg_catalog") == 0 && tableinfo.relreplident !=
'n')))
3494 const char *s =
_(
"Replica Identity");
3498 tableinfo.relreplident ==
'f' ?
"FULL" :
3499 tableinfo.relreplident ==
'n' ?
"NOTHING" :
3506 if (
verbose && tableinfo.relkind != RELKIND_MATVIEW && tableinfo.hasoids)
3523 tableinfo.reloptions && tableinfo.reloptions[0] !=
'\0')
3525 const char *t =
_(
"Options");
3538 if (printTableInitialized)
3561 if (relkind == RELKIND_RELATION ||
3562 relkind == RELKIND_MATVIEW ||
3563 relkind == RELKIND_INDEX ||
3564 relkind == RELKIND_PARTITIONED_TABLE ||
3565 relkind == RELKIND_PARTITIONED_INDEX ||
3566 relkind == RELKIND_TOASTVALUE)
3579 "SELECT spcname FROM pg_catalog.pg_tablespace\n"
3632 const char align =
'l';
3640 "SELECT r.rolname, r.rolsuper, r.rolinherit,\n"
3641 " r.rolcreaterole, r.rolcreatedb, r.rolcanlogin,\n"
3642 " r.rolconnlimit, r.rolvaliduntil");
3658 if (!showSystem && !pattern)
3662 NULL,
"r.rolname", NULL, NULL,
3676 attr =
pg_malloc0((nrows + 1) *
sizeof(*attr));
3686 for (
i = 0;
i < nrows;
i++)
3748 for (
i = 0;
i < nrows;
i++)
3779 "pg_catalog.array_to_string(setconfig, E'\\n') AS \"%s\"\n"
3780 "FROM pg_catalog.pg_db_role_setting s\n"
3781 "LEFT JOIN pg_catalog.pg_database d ON d.oid = setdatabase\n"
3782 "LEFT JOIN pg_catalog.pg_roles r ON r.oid = setrole\n",
3787 NULL,
"r.rolname", NULL, NULL, &havewhere, 1))
3790 NULL,
"d.datname", NULL, NULL,
3808 if (pattern && pattern2)
3809 pg_log_error(
"Did not find any settings for role \"%s\" and database \"%s\".",
3812 pg_log_error(
"Did not find any settings for role \"%s\".",
3819 myopt.
title =
_(
"List of settings");
3846 "SELECT m.rolname AS \"%s\", r.rolname AS \"%s\",\n"
3847 " pg_catalog.concat_ws(', ',\n",
3853 " CASE WHEN pam.admin_option THEN 'ADMIN' END,\n"
3854 " CASE WHEN pam.inherit_option THEN 'INHERIT' END,\n"
3855 " CASE WHEN pam.set_option THEN 'SET' END\n");
3858 " CASE WHEN pam.admin_option THEN 'ADMIN' END,\n"
3859 " CASE WHEN m.rolinherit THEN 'INHERIT' END,\n"
3864 " g.rolname AS \"%s\"\n",
3869 "FROM pg_catalog.pg_roles m\n"
3870 " JOIN pg_catalog.pg_auth_members pam ON (pam.member = m.oid)\n"
3871 " LEFT JOIN pg_catalog.pg_roles r ON (pam.roleid = r.oid)\n"
3872 " LEFT JOIN pg_catalog.pg_roles g ON (pam.grantor = g.oid)\n");
3874 if (!showSystem && !pattern)
3878 NULL,
"m.rolname", NULL, NULL,
3892 myopt.
title =
_(
"List of role grants");
3919 bool showTables = strchr(tabtypes,
't') != NULL;
3920 bool showIndexes = strchr(tabtypes,
'i') != NULL;
3921 bool showViews = strchr(tabtypes,
'v') != NULL;
3922 bool showMatViews = strchr(tabtypes,
'm') != NULL;
3923 bool showSeq = strchr(tabtypes,
's') != NULL;
3924 bool showForeign = strchr(tabtypes,
'E') != NULL;
3930 bool translate_columns[] = {
false,
false,
true,
false,
false,
false,
false,
false,
false};
3933 if (!(showTables || showIndexes || showViews || showMatViews || showSeq || showForeign))
3934 showTables = showViews = showMatViews = showSeq = showForeign =
true;
3939 "SELECT n.nspname as \"%s\",\n"
3940 " c.relname as \"%s\",\n"
3948 " WHEN " CppAsString2(RELKIND_FOREIGN_TABLE)
" THEN '%s'"
3949 " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE)
" THEN '%s'"
3950 " WHEN " CppAsString2(RELKIND_PARTITIONED_INDEX)
" THEN '%s'"
3952 " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
3971 ",\n c2.relname as \"%s\"",
3982 ",\n CASE c.relpersistence WHEN 'p' THEN '%s' WHEN 't' THEN '%s' WHEN 'u' THEN '%s' END as \"%s\"",
3987 translate_columns[cols_so_far] =
true;
3999 (showTables || showMatViews || showIndexes))
4001 ",\n am.amname as \"%s\"",
4005 ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_table_size(c.oid)) as \"%s\""
4006 ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
4012 "\nFROM pg_catalog.pg_class c"
4013 "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
4016 (showTables || showMatViews || showIndexes))
4018 "\n LEFT JOIN pg_catalog.pg_am am ON am.oid = c.relam");
4022 "\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
4023 "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
4031 if (showSystem || pattern)
4043 if (showSystem || pattern)
4051 if (!showSystem && !pattern)
4053 " AND n.nspname !~ '^pg_toast'\n"
4054 " AND n.nspname <> 'information_schema'\n");
4057 "n.nspname",
"c.relname", NULL,
4058 "pg_catalog.pg_table_is_visible(c.oid)",
4080 pg_log_error(
"Did not find any relation named \"%s\".",
4087 myopt.
title =
_(
"List of relations");
4117 bool showTables = strchr(reltypes,
't') != NULL;
4118 bool showIndexes = strchr(reltypes,
'i') != NULL;
4119 bool showNested = strchr(reltypes,
'n') != NULL;
4124 bool translate_columns[] = {
false,
false,
false,
false,
false,
false,
false,
false,
false,
false};
4125 const char *tabletitle;
4126 bool mixed_output =
false;
4135 pg_log_error(
"The server (version %s) does not support declarative table partitioning.",
4137 sverbuf,
sizeof(sverbuf)));
4142 if (!showTables && !showIndexes)
4143 showTables = showIndexes =
true;
4145 if (showIndexes && !showTables)
4146 tabletitle =
_(
"List of partitioned indexes");
4147 else if (showTables && !showIndexes)
4148 tabletitle =
_(
"List of partitioned tables");
4152 tabletitle =
_(
"List of partitioned relations");
4153 mixed_output =
true;
4159 "SELECT n.nspname as \"%s\",\n"
4160 " c.relname as \"%s\",\n"
4161 " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
4169 ",\n CASE c.relkind"
4170 " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE)
" THEN '%s'"
4171 " WHEN " CppAsString2(RELKIND_PARTITIONED_INDEX)
" THEN '%s'"
4177 translate_columns[3] =
true;
4180 if (showNested || pattern)
4182 ",\n inh.inhparent::pg_catalog.regclass as \"%s\"",
4187 ",\n c2.oid::pg_catalog.regclass as \"%s\"",
4202 ",\n s.dps as \"%s\"",
4205 ",\n s.tps as \"%s\"",
4211 ",\n s.tps as \"%s\"",
4215 ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
4220 "\nFROM pg_catalog.pg_class c"
4221 "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
4225 "\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
4226 "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
4228 if (showNested || pattern)
4230 "\n LEFT JOIN pg_catalog.pg_inherits inh ON c.oid = inh.inhrelid");
4235 "\n LEFT JOIN pg_catalog.pg_am am ON c.relam = am.oid");
4240 ",\n LATERAL (WITH RECURSIVE d\n"
4241 " AS (SELECT inhrelid AS oid, 1 AS level\n"
4242 " FROM pg_catalog.pg_inherits\n"
4243 " WHERE inhparent = c.oid\n"
4245 " SELECT inhrelid, level + 1\n"
4246 " FROM pg_catalog.pg_inherits i\n"
4247 " JOIN d ON i.inhparent = d.oid)\n"
4248 " SELECT pg_catalog.pg_size_pretty(sum(pg_catalog.pg_table_size("
4249 "d.oid))) AS tps,\n"
4250 " pg_catalog.pg_size_pretty(sum("
4251 "\n CASE WHEN d.level = 1"
4252 " THEN pg_catalog.pg_table_size(d.oid) ELSE 0 END)) AS dps\n"
4259 ",\n LATERAL (SELECT pg_catalog.pg_size_pretty(sum("
4260 "\n CASE WHEN ppt.isleaf AND ppt.level = 1"
4261 "\n THEN pg_catalog.pg_table_size(ppt.relid)"
4262 " ELSE 0 END)) AS dps"
4263 ",\n pg_catalog.pg_size_pretty(sum("
4264 "pg_catalog.pg_table_size(ppt.relid))) AS tps"
4265 "\n FROM pg_catalog.pg_partition_tree(c.oid) ppt) s");
4278 " AND NOT c.relispartition\n" :
"");
4282 " AND n.nspname !~ '^pg_toast'\n"
4283 " AND n.nspname <> 'information_schema'\n");
4286 "n.nspname",
"c.relname", NULL,
4287 "pg_catalog.pg_table_is_visible(c.oid)",
4295 mixed_output ?
"\"Type\" DESC, " :
"",
4296 showNested || pattern ?
"\"Parent name\" NULLS FIRST, " :
"");
4334 "SELECT l.lanname AS \"%s\",\n"
4335 " pg_catalog.pg_get_userbyid(l.lanowner) as \"%s\",\n"
4336 " l.lanpltrusted AS \"%s\"",
4344 ",\n NOT l.lanispl AS \"%s\",\n"
4345 " l.lanplcallfoid::pg_catalog.regprocedure AS \"%s\",\n"
4346 " l.lanvalidator::pg_catalog.regprocedure AS \"%s\",\n "
4347 "l.laninline::pg_catalog.regprocedure AS \"%s\",\n ",
4356 ",\n d.description AS \"%s\""
4357 "\nFROM pg_catalog.pg_language l\n"
4358 "LEFT JOIN pg_catalog.pg_description d\n"
4359 " ON d.classoid = l.tableoid AND d.objoid = l.oid\n"
4360 " AND d.objsubid = 0\n",
4366 NULL,
"l.lanname", NULL, NULL,
4374 if (!showSystem && !pattern)
4385 myopt.
title =
_(
"List of languages");
4410 "SELECT n.nspname as \"%s\",\n"
4411 " t.typname as \"%s\",\n"
4412 " pg_catalog.format_type(t.typbasetype, t.typtypmod) as \"%s\",\n"
4413 " (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type bt\n"
4414 " WHERE c.oid = t.typcollation AND bt.oid = t.typbasetype AND t.typcollation <> bt.typcollation) as \"%s\",\n"
4415 " CASE WHEN t.typnotnull THEN 'not null' END as \"%s\",\n"
4416 " t.typdefault as \"%s\",\n"
4417 " pg_catalog.array_to_string(ARRAY(\n"
4418 " SELECT pg_catalog.pg_get_constraintdef(r.oid, true) FROM pg_catalog.pg_constraint r WHERE t.oid = r.contypid AND r.contype = 'c' ORDER BY r.conname\n"
4419 " ), ' ') as \"%s\"",
4433 ",\n d.description as \"%s\"",
4438 "\nFROM pg_catalog.pg_type t\n"
4439 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
4443 " LEFT JOIN pg_catalog.pg_description d "
4444 "ON d.classoid = t.tableoid AND d.objoid = t.oid "
4445 "AND d.objsubid = 0\n");
4449 if (!showSystem && !pattern)
4451 " AND n.nspname <> 'information_schema'\n");
4454 "n.nspname",
"t.typname", NULL,
4455 "pg_catalog.pg_type_is_visible(t.oid)",
4469 myopt.
title =
_(
"List of domains");
4489 static const bool translate_columns[] =
4490 {
false,
false,
false,
false,
true,
false};
4495 "SELECT n.nspname AS \"%s\",\n"
4496 " c.conname AS \"%s\",\n"
4497 " pg_catalog.pg_encoding_to_char(c.conforencoding) AS \"%s\",\n"
4498 " pg_catalog.pg_encoding_to_char(c.contoencoding) AS \"%s\",\n"
4499 " CASE WHEN c.condefault THEN '%s'\n"
4500 " ELSE '%s' END AS \"%s\"",
4510 ",\n d.description AS \"%s\"",
4514 "\nFROM pg_catalog.pg_conversion c\n"
4515 " JOIN pg_catalog.pg_namespace n "
4516 "ON n.oid = c.connamespace\n");
4520 "LEFT JOIN pg_catalog.pg_description d "
4521 "ON d.classoid = c.tableoid\n"
4522 " AND d.objoid = c.oid "
4523 "AND d.objsubid = 0\n");
4527 if (!showSystem && !pattern)
4529 " AND n.nspname <> 'information_schema'\n");
4532 "n.nspname",
"c.conname", NULL,
4533 "pg_catalog.pg_conversion_is_visible(c.oid)",
4547 myopt.
title =
_(
"List of conversions");
4573 "SELECT s.name AS \"%s\", "
4574 "pg_catalog.current_setting(s.name) AS \"%s\"",
4581 ", s.vartype AS \"%s\", s.context AS \"%s\", ",
4595 " LEFT JOIN pg_catalog.pg_parameter_acl p\n"
4596 " ON pg_catalog.lower(s.name) = p.parname\n");
4601 NULL,
"pg_catalog.lower(s.name)", NULL,
4605 " s.setting IS DISTINCT FROM s.boot_val\n");
4615 myopt.
title =
_(
"List of configuration parameters");
4617 myopt.
title =
_(
"List of non-default configuration parameters");
4637 static const bool translate_columns[] =
4638 {
false,
false,
false,
true,
false,
false,
false};
4644 pg_log_error(
"The server (version %s) does not support event triggers.",
4646 sverbuf,
sizeof(sverbuf)));
4653 "SELECT evtname as \"%s\", "
4654 "evtevent as \"%s\", "
4655 "pg_catalog.pg_get_userbyid(e.evtowner) as \"%s\",\n"
4656 " case evtenabled when 'O' then '%s'"
4657 " when 'R' then '%s'"
4658 " when 'A' then '%s'"
4659 " when 'D' then '%s' end as \"%s\",\n"
4660 " e.evtfoid::pg_catalog.regproc as \"%s\", "
4661 "pg_catalog.array_to_string(array(select x"
4662 " from pg_catalog.unnest(evttags) as t(x)), ', ') as \"%s\"",
4675 ",\npg_catalog.obj_description(e.oid, 'pg_event_trigger') as \"%s\"",
4678 "\nFROM pg_catalog.pg_event_trigger e ");
4681 NULL,
"evtname", NULL, NULL,
4695 myopt.
title =
_(
"List of event triggers");
4722 pg_log_error(
"The server (version %s) does not support extended statistics.",
4724 sverbuf,
sizeof(sverbuf)));
4731 "es.stxnamespace::pg_catalog.regnamespace::pg_catalog.text AS \"%s\", \n"
4732 "es.stxname AS \"%s\", \n",
4738 "pg_catalog.format('%%s FROM %%s', \n"
4739 " pg_catalog.pg_get_statisticsobjdef_columns(es.oid), \n"
4740 " es.stxrelid::pg_catalog.regclass) AS \"%s\"",
4744 "pg_catalog.format('%%s FROM %%s', \n"
4745 " (SELECT pg_catalog.string_agg(pg_catalog.quote_ident(a.attname),', ') \n"
4746 " FROM pg_catalog.unnest(es.stxkeys) s(attnum) \n"
4747 " JOIN pg_catalog.pg_attribute a \n"
4748 " ON (es.stxrelid = a.attrelid \n"
4749 " AND a.attnum = s.attnum \n"
4750 " AND NOT a.attisdropped)), \n"
4751 "es.stxrelid::pg_catalog.regclass) AS \"%s\"",
4755 ",\nCASE WHEN 'd' = any(es.stxkind) THEN 'defined' \n"
4757 "CASE WHEN 'f' = any(es.stxkind) THEN 'defined' \n"
4768 ",\nCASE WHEN 'm' = any(es.stxkind) THEN 'defined' \n"
4774 " \nFROM pg_catalog.pg_statistic_ext es \n");
4778 "es.stxnamespace::pg_catalog.regnamespace::pg_catalog.text",
"es.stxname",
4779 NULL,
"pg_catalog.pg_statistics_obj_is_visible(es.oid)",
4793 myopt.
title =
_(
"List of extended statistics");
4813 static const bool translate_columns[] = {
false,
false,
false,
true,
false};
4818 "SELECT pg_catalog.format_type(castsource, NULL) AS \"%s\",\n"
4819 " pg_catalog.format_type(casttarget, NULL) AS \"%s\",\n",
4829 " CASE WHEN c.castmethod = '%c' THEN '(binary coercible)'\n"
4830 " WHEN c.castmethod = '%c' THEN '(with inout)'\n"
4832 " END AS \"%s\",\n",
4833 COERCION_METHOD_BINARY,
4834 COERCION_METHOD_INOUT,
4838 " CASE WHEN c.castcontext = '%c' THEN '%s'\n"
4839 " WHEN c.castcontext = '%c' THEN '%s'\n"
4842 COERCION_CODE_EXPLICIT,
4844 COERCION_CODE_ASSIGNMENT,
4851 ",\n d.description AS \"%s\"",
4859 "\nFROM pg_catalog.pg_cast c LEFT JOIN pg_catalog.pg_proc p\n"
4860 " ON c.castfunc = p.oid\n"
4861 " LEFT JOIN pg_catalog.pg_type ts\n"
4862 " ON c.castsource = ts.oid\n"
4863 " LEFT JOIN pg_catalog.pg_namespace ns\n"
4864 " ON ns.oid = ts.typnamespace\n"
4865 " LEFT JOIN pg_catalog.pg_type tt\n"
4866 " ON c.casttarget = tt.oid\n"
4867 " LEFT JOIN pg_catalog.pg_namespace nt\n"
4868 " ON nt.oid = tt.typnamespace\n");
4872 " LEFT JOIN pg_catalog.pg_description d\n"
4873 " ON d.classoid = c.tableoid AND d.objoid = "
4874 "c.oid AND d.objsubid = 0\n");
4883 "ns.nspname",
"ts.typname",
4884 "pg_catalog.format_type(ts.oid, NULL)",
4885 "pg_catalog.pg_type_is_visible(ts.oid)",
4892 "nt.nspname",
"tt.typname",
4893 "pg_catalog.format_type(tt.oid, NULL)",
4894 "pg_catalog.pg_type_is_visible(tt.oid)",
4905 myopt.
title =
_(
"List of casts");
4931 static const bool translate_columns[] = {
false,
false,
false,
false,
false,
false,
false,
true,
false};
4937 " n.nspname AS \"%s\",\n"
4938 " c.collname AS \"%s\",\n",
4944 " CASE c.collprovider WHEN 'd' THEN 'default' WHEN 'b' THEN 'builtin' WHEN 'c' THEN 'libc' WHEN 'i' THEN 'icu' END AS \"%s\",\n",
4948 " 'libc' AS \"%s\",\n",
4952 " c.collcollate AS \"%s\",\n"
4953 " c.collctype AS \"%s\",\n",
4959 " c.colllocale AS \"%s\",\n",
4963 " c.colliculocale AS \"%s\",\n",
4967 " c.collcollate AS \"%s\",\n",
4972 " c.collicurules AS \"%s\",\n",
4976 " NULL AS \"%s\",\n",
4981 " CASE WHEN c.collisdeterministic THEN '%s' ELSE '%s' END AS \"%s\"",
4992 ",\n pg_catalog.obj_description(c.oid, 'pg_collation') AS \"%s\"",
4996 "\nFROM pg_catalog.pg_collation c, pg_catalog.pg_namespace n\n"
4997 "WHERE n.oid = c.collnamespace\n");
4999 if (!showSystem && !pattern)
5001 " AND n.nspname <> 'information_schema'\n");
5009 appendPQExpBufferStr(&
buf,
" AND c.collencoding IN (-1, pg_catalog.pg_char_to_encoding(pg_catalog.getdatabaseencoding()))\n");
5012 "n.nspname",
"c.collname", NULL,
5013 "pg_catalog.pg_collation_is_visible(c.oid)",
5027 myopt.
title =
_(
"List of collations");
5049 int pub_schema_tuples = 0;
5050 char **footers = NULL;
5054 "SELECT n.nspname AS \"%s\",\n"
5055 " pg_catalog.pg_get_userbyid(n.nspowner) AS \"%s\"",
5064 ",\n pg_catalog.obj_description(n.oid, 'pg_namespace') AS \"%s\"",
5069 "\nFROM pg_catalog.pg_namespace n\n");
5071 if (!showSystem && !pattern)
5073 "WHERE n.nspname !~ '^pg_' AND n.nspname <> 'information_schema'\n");
5076 !showSystem && !pattern,
false,
5077 NULL,
"n.nspname", NULL,
5088 myopt.
title =
_(
"List of schemas");
5098 "FROM pg_catalog.pg_publication p\n"
5099 " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n"
5100 " JOIN pg_catalog.pg_namespace n ON n.oid = pn.pnnspid \n"
5101 "WHERE n.nspname = '%s'\n"
5110 if (pub_schema_tuples > 0)
5117 footers = (
char **)
pg_malloc((1 + pub_schema_tuples + 1) *
sizeof(
char *));
5121 for (
i = 0;
i < pub_schema_tuples;
i++)
5129 footers[
i + 1] = NULL;
5144 char **footer = NULL;
5146 for (footer = footers; *footer; footer++)