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)",
128 myopt.
title =
_(
"List of aggregate functions");
147 static const bool translate_columns[] = {
false,
true,
false,
false};
153 pg_log_error(
"The server (version %s) does not support access methods.",
155 sverbuf,
sizeof(sverbuf)));
162 "SELECT amname AS \"%s\",\n"
164 " WHEN 'i' THEN '%s'"
165 " WHEN 't' THEN '%s'"
175 ",\n amhandler AS \"%s\",\n"
176 " pg_catalog.obj_description(oid, 'pg_am') AS \"%s\"",
182 "\nFROM pg_catalog.pg_am\n");
185 NULL,
"amname", NULL,
201 myopt.
title =
_(
"List of access methods");
226 "SELECT spcname AS \"%s\",\n"
227 " pg_catalog.pg_get_userbyid(spcowner) AS \"%s\",\n"
228 " pg_catalog.pg_tablespace_location(oid) AS \"%s\"",
238 ",\n spcoptions AS \"%s\""
239 ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_tablespace_size(oid)) AS \"%s\""
240 ",\n pg_catalog.shobj_description(oid, 'pg_tablespace') AS \"%s\"",
247 "\nFROM pg_catalog.pg_tablespace\n");
250 NULL,
"spcname", NULL,
266 myopt.
title =
_(
"List of tablespaces");
292 char **arg_patterns,
int num_arg_patterns,
295 bool showAggregate = strchr(functypes,
'a') != NULL;
296 bool showNormal = strchr(functypes,
'n') != NULL;
297 bool showProcedure = strchr(functypes,
'p') != NULL;
298 bool showTrigger = strchr(functypes,
't') != NULL;
299 bool showWindow = strchr(functypes,
'w') != NULL;
304 static const bool translate_columns[] = {
false,
false,
false,
false,
true,
true,
true,
false,
true,
false,
false,
false,
false};
307 static const bool translate_columns_pre_96[] = {
false,
false,
false,
false,
true,
true,
false,
true,
false,
false,
false,
false};
309 if (strlen(functypes) != strspn(functypes,
"anptwS+"))
319 pg_log_error(
"\\df does not take a \"%c\" option with server version %s",
322 sverbuf,
sizeof(sverbuf)));
326 if (!showAggregate && !showNormal && !showProcedure && !showTrigger && !showWindow)
328 showAggregate = showNormal = showTrigger = showWindow =
true;
330 showProcedure =
true;
336 "SELECT n.nspname as \"%s\",\n"
337 " p.proname as \"%s\",\n",
343 " pg_catalog.pg_get_function_result(p.oid) as \"%s\",\n"
344 " pg_catalog.pg_get_function_arguments(p.oid) as \"%s\",\n"
346 " WHEN 'a' THEN '%s'\n"
347 " WHEN 'w' THEN '%s'\n"
348 " WHEN 'p' THEN '%s'\n"
361 " pg_catalog.pg_get_function_result(p.oid) as \"%s\",\n"
362 " pg_catalog.pg_get_function_arguments(p.oid) as \"%s\",\n"
364 " WHEN p.proisagg THEN '%s'\n"
365 " WHEN p.proiswindow THEN '%s'\n"
366 " WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN '%s'\n"
382 " WHEN p.provolatile = 'i' THEN '%s'\n"
383 " WHEN p.provolatile = 's' THEN '%s'\n"
384 " WHEN p.provolatile = 'v' THEN '%s'\n"
393 " WHEN p.proparallel = 'r' THEN '%s'\n"
394 " WHEN p.proparallel = 's' THEN '%s'\n"
395 " WHEN p.proparallel = 'u' THEN '%s'\n"
402 ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\""
403 ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"",
411 ",\n l.lanname as \"%s\"",
414 ",\n CASE WHEN l.lanname IN ('internal', 'c') THEN p.prosrc END as \"%s\"",
417 ",\n pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"",
422 "\nFROM pg_catalog.pg_proc p"
423 "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n");
425 for (
int i = 0;
i < num_arg_patterns;
i++)
428 " LEFT JOIN pg_catalog.pg_type t%d ON t%d.oid = p.proargtypes[%d]\n"
429 " LEFT JOIN pg_catalog.pg_namespace nt%d ON nt%d.oid = t%d.typnamespace\n",
435 " LEFT JOIN pg_catalog.pg_language l ON l.oid = p.prolang\n");
440 if (showNormal && showAggregate && showProcedure && showTrigger && showWindow)
497 bool needs_or =
false;
515 "p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype\n");
538 "n.nspname",
"p.proname", NULL,
539 "pg_catalog.pg_function_is_visible(p.oid)",
543 for (
int i = 0;
i < num_arg_patterns;
i++)
545 if (strcmp(arg_patterns[
i],
"-") != 0)
557 snprintf(nspname,
sizeof(nspname),
"nt%d.nspname",
i);
560 "pg_catalog.format_type(t%d.oid, NULL)",
i);
562 "pg_catalog.pg_type_is_visible(t%d.oid)",
i);
577 if (!showSystem && !func_pattern)
579 " AND n.nspname <> 'information_schema'\n");
589 myopt.
title =
_(
"List of functions");
628 "SELECT n.nspname as \"%s\",\n"
629 " pg_catalog.format_type(t.oid, NULL) AS \"%s\",\n",
635 " t.typname AS \"%s\",\n"
636 " CASE WHEN t.typrelid != 0\n"
637 " THEN CAST('tuple' AS pg_catalog.text)\n"
638 " WHEN t.typlen < 0\n"
639 " THEN CAST('var' AS pg_catalog.text)\n"
640 " ELSE CAST(t.typlen AS pg_catalog.text)\n"
642 " pg_catalog.array_to_string(\n"
644 " SELECT e.enumlabel\n"
645 " FROM pg_catalog.pg_enum e\n"
646 " WHERE e.enumtypid = t.oid\n"
647 " ORDER BY e.enumsortorder\n"
651 " pg_catalog.pg_get_userbyid(t.typowner) AS \"%s\",\n",
661 " pg_catalog.obj_description(t.oid, 'pg_type') as \"%s\"\n",
665 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
673 " FROM pg_catalog.pg_class c "
674 "WHERE c.oid = t.typrelid))\n");
679 if (pattern == NULL || strstr(pattern,
"[]") == NULL)
680 appendPQExpBufferStr(&
buf,
" AND NOT EXISTS(SELECT 1 FROM pg_catalog.pg_type el WHERE el.oid = t.typelem AND el.typarray = t.oid)\n");
682 if (!showSystem && !pattern)
684 " AND n.nspname <> 'information_schema'\n");
689 "n.nspname",
"t.typname",
690 "pg_catalog.format_type(t.oid, NULL)",
691 "pg_catalog.pg_type_is_visible(t.oid)",
706 myopt.
title =
_(
"List of data types");
727 static const char *
const typename_map[] = {
733 "decimal",
"numeric",
734 "float",
"double precision",
741 "bool[]",
"boolean[]",
742 "decimal[]",
"numeric[]",
743 "float[]",
"double precision[]",
744 "float4[]",
"real[]",
745 "float8[]",
"double precision[]",
746 "int[]",
"integer[]",
747 "int2[]",
"smallint[]",
748 "int4[]",
"integer[]",
749 "int8[]",
"bigint[]",
750 "time[]",
"time without time zone[]",
751 "timetz[]",
"time with time zone[]",
752 "timestamp[]",
"timestamp without time zone[]",
753 "timestamptz[]",
"timestamp with time zone[]",
754 "varbit[]",
"bit varying[]",
755 "varchar[]",
"character varying[]",
761 for (
int i = 0; typename_map[
i] != NULL;
i += 2)
764 return typename_map[
i + 1];
776 char **arg_patterns,
int num_arg_patterns,
802 "SELECT n.nspname as \"%s\",\n"
803 " o.oprname AS \"%s\",\n"
804 " CASE WHEN o.oprkind='l' THEN NULL ELSE pg_catalog.format_type(o.oprleft, NULL) END AS \"%s\",\n"
805 " CASE WHEN o.oprkind='r' THEN NULL ELSE pg_catalog.format_type(o.oprright, NULL) END AS \"%s\",\n"
806 " pg_catalog.format_type(o.oprresult, NULL) AS \"%s\",\n",
815 " o.oprcode AS \"%s\",\n",
819 " coalesce(pg_catalog.obj_description(o.oid, 'pg_operator'),\n"
820 " pg_catalog.obj_description(o.oprcode, 'pg_proc')) AS \"%s\"\n"
821 "FROM pg_catalog.pg_operator o\n"
822 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = o.oprnamespace\n",
825 if (num_arg_patterns >= 2)
827 num_arg_patterns = 2;
829 " LEFT JOIN pg_catalog.pg_type t0 ON t0.oid = o.oprleft\n"
830 " LEFT JOIN pg_catalog.pg_namespace nt0 ON nt0.oid = t0.typnamespace\n"
831 " LEFT JOIN pg_catalog.pg_type t1 ON t1.oid = o.oprright\n"
832 " LEFT JOIN pg_catalog.pg_namespace nt1 ON nt1.oid = t1.typnamespace\n");
834 else if (num_arg_patterns == 1)
837 " LEFT JOIN pg_catalog.pg_type t0 ON t0.oid = o.oprright\n"
838 " LEFT JOIN pg_catalog.pg_namespace nt0 ON nt0.oid = t0.typnamespace\n");
841 if (!showSystem && !oper_pattern)
843 " AND n.nspname <> 'information_schema'\n");
846 !showSystem && !oper_pattern,
true,
847 "n.nspname",
"o.oprname", NULL,
848 "pg_catalog.pg_operator_is_visible(o.oid)",
852 if (num_arg_patterns == 1)
855 for (
int i = 0;
i < num_arg_patterns;
i++)
857 if (strcmp(arg_patterns[
i],
"-") != 0)
869 snprintf(nspname,
sizeof(nspname),
"nt%d.nspname",
i);
872 "pg_catalog.format_type(t%d.oid, NULL)",
i);
874 "pg_catalog.pg_type_is_visible(t%d.oid)",
i);
897 myopt.
title =
_(
"List of operators");
927 " d.datname as \"%s\",\n"
928 " pg_catalog.pg_get_userbyid(d.datdba) as \"%s\",\n"
929 " pg_catalog.pg_encoding_to_char(d.encoding) as \"%s\",\n",
935 " CASE d.datlocprovider WHEN 'c' THEN 'libc' WHEN 'i' THEN 'icu' END AS \"%s\",\n",
939 " 'libc' AS \"%s\",\n",
942 " d.datcollate as \"%s\",\n"
943 " d.datctype as \"%s\",\n",
948 " d.daticulocale as \"%s\",\n",
952 " NULL as \"%s\",\n",
956 " d.daticurules as \"%s\",\n",
960 " NULL as \"%s\",\n",
966 ",\n CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT')\n"
967 " THEN pg_catalog.pg_size_pretty(pg_catalog.pg_database_size(d.datname))\n"
968 " ELSE 'No Access'\n"
970 ",\n t.spcname as \"%s\""
971 ",\n pg_catalog.shobj_description(d.oid, 'pg_database') as \"%s\"",
976 "\nFROM pg_catalog.pg_database d\n");
979 " JOIN pg_catalog.pg_tablespace t on d.dattablespace = t.oid\n");
984 NULL,
"d.datname", NULL, NULL,
999 myopt.
title =
_(
"List of databases");
1019 static const bool translate_columns[] = {
false,
false,
true,
false,
false,
false};
1027 "SELECT n.nspname as \"%s\",\n"
1028 " c.relname as \"%s\",\n"
1034 " WHEN " CppAsString2(RELKIND_FOREIGN_TABLE)
" THEN '%s'"
1035 " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE)
" THEN '%s'"
1051 ",\n pg_catalog.array_to_string(ARRAY(\n"
1052 " SELECT attname || E':\\n ' || pg_catalog.array_to_string(attacl, E'\\n ')\n"
1053 " FROM pg_catalog.pg_attribute a\n"
1054 " WHERE attrelid = c.oid AND NOT attisdropped AND attacl IS NOT NULL\n"
1055 " ), E'\\n') AS \"%s\"",
1060 ",\n pg_catalog.array_to_string(ARRAY(\n"
1062 " || CASE WHEN polcmd != '*' THEN\n"
1063 " E' (' || polcmd::pg_catalog.text || E'):'\n"
1066 " || CASE WHEN polqual IS NOT NULL THEN\n"
1067 " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n"
1070 " || CASE WHEN polwithcheck IS NOT NULL THEN\n"
1071 " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n"
1074 " || CASE WHEN polroles <> '{0}' THEN\n"
1075 " E'\\n to: ' || pg_catalog.array_to_string(\n"
1078 " FROM pg_catalog.pg_roles\n"
1079 " WHERE oid = ANY (polroles)\n"
1084 " FROM pg_catalog.pg_policy pol\n"
1085 " WHERE polrelid = c.oid), E'\\n')\n"
1091 ",\n pg_catalog.array_to_string(ARRAY(\n"
1093 " || CASE WHEN NOT polpermissive THEN\n"
1094 " E' (RESTRICTIVE)'\n"
1096 " || CASE WHEN polcmd != '*' THEN\n"
1097 " E' (' || polcmd::pg_catalog.text || E'):'\n"
1100 " || CASE WHEN polqual IS NOT NULL THEN\n"
1101 " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n"
1104 " || CASE WHEN polwithcheck IS NOT NULL THEN\n"
1105 " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n"
1108 " || CASE WHEN polroles <> '{0}' THEN\n"
1109 " E'\\n to: ' || pg_catalog.array_to_string(\n"
1112 " FROM pg_catalog.pg_roles\n"
1113 " WHERE oid = ANY (polroles)\n"
1118 " FROM pg_catalog.pg_policy pol\n"
1119 " WHERE polrelid = c.oid), E'\\n')\n"
1124 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
1125 "WHERE c.relkind IN ("
1133 if (!showSystem && !pattern)
1135 " AND n.nspname <> 'information_schema'\n");
1138 "n.nspname",
"c.relname", NULL,
1139 "pg_catalog.pg_table_is_visible(c.oid)",
1179 static const bool translate_columns[] = {
false,
false,
true,
false};
1184 "SELECT pg_catalog.pg_get_userbyid(d.defaclrole) AS \"%s\",\n"
1185 " n.nspname AS \"%s\",\n"
1186 " 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"
1198 DEFACLOBJ_NAMESPACE,
1205 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.defaclnamespace\n");
1210 "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");
1421 myopt.
title =
_(
"Object descriptions");
1458 "FROM pg_catalog.pg_class c\n"
1459 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n");
1461 if (!showSystem && !pattern)
1463 " AND n.nspname <> 'information_schema'\n");
1466 "n.nspname",
"c.relname", NULL,
1467 "pg_catalog.pg_table_is_visible(c.oid)",
1486 pg_log_error(
"Did not find any relation named \"%s\".",
1498 const char *nspname;
1530 const char *relationname,
1534 bool retval =
false;
1539 bool printTableInitialized =
false;
1541 char *view_def = NULL;
1546 int attname_col = -1,
1549 attnotnull_col = -1,
1551 attidentity_col = -1,
1552 attgenerated_col = -1,
1553 isindexkey_col = -1,
1556 attstorage_col = -1,
1557 attcompression_col = -1,
1558 attstattarget_col = -1,
1569 bool forcerowsecurity;
1575 char relpersistence;
1579 bool show_column_details =
false;
1593 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1594 "c.relhastriggers, c.relrowsecurity, c.relforcerowsecurity, "
1595 "false AS relhasoids, c.relispartition, %s, c.reltablespace, "
1596 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
1597 "c.relpersistence, c.relreplident, am.amname\n"
1598 "FROM pg_catalog.pg_class c\n "
1599 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1600 "LEFT JOIN pg_catalog.pg_am am ON (c.relam = am.oid)\n"
1601 "WHERE c.oid = '%s';",
1603 "pg_catalog.array_to_string(c.reloptions || "
1604 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1611 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1612 "c.relhastriggers, c.relrowsecurity, c.relforcerowsecurity, "
1613 "c.relhasoids, c.relispartition, %s, c.reltablespace, "
1614 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
1615 "c.relpersistence, c.relreplident\n"
1616 "FROM pg_catalog.pg_class c\n "
1617 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1618 "WHERE c.oid = '%s';",
1620 "pg_catalog.array_to_string(c.reloptions || "
1621 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1628 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1629 "c.relhastriggers, c.relrowsecurity, c.relforcerowsecurity, "
1630 "c.relhasoids, false as relispartition, %s, c.reltablespace, "
1631 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
1632 "c.relpersistence, c.relreplident\n"
1633 "FROM pg_catalog.pg_class c\n "
1634 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1635 "WHERE c.oid = '%s';",
1637 "pg_catalog.array_to_string(c.reloptions || "
1638 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1645 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1646 "c.relhastriggers, false, false, c.relhasoids, "
1647 "false as relispartition, %s, c.reltablespace, "
1648 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
1649 "c.relpersistence, c.relreplident\n"
1650 "FROM pg_catalog.pg_class c\n "
1651 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1652 "WHERE c.oid = '%s';",
1654 "pg_catalog.array_to_string(c.reloptions || "
1655 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1662 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1663 "c.relhastriggers, false, false, c.relhasoids, "
1664 "false as relispartition, %s, c.reltablespace, "
1665 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
1666 "c.relpersistence\n"
1667 "FROM pg_catalog.pg_class c\n "
1668 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1669 "WHERE c.oid = '%s';",
1671 "pg_catalog.array_to_string(c.reloptions || "
1672 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1685 pg_log_error(
"Did not find any relation with OID %s.", oid);
1691 tableinfo.hasindex = strcmp(
PQgetvalue(
res, 0, 2),
"t") == 0;
1692 tableinfo.hasrules = strcmp(
PQgetvalue(
res, 0, 3),
"t") == 0;
1693 tableinfo.hastriggers = strcmp(
PQgetvalue(
res, 0, 4),
"t") == 0;
1694 tableinfo.rowsecurity = strcmp(
PQgetvalue(
res, 0, 5),
"t") == 0;
1695 tableinfo.forcerowsecurity = strcmp(
PQgetvalue(
res, 0, 6),
"t") == 0;
1696 tableinfo.hasoids = strcmp(
PQgetvalue(
res, 0, 7),
"t") == 0;
1697 tableinfo.ispartition = strcmp(
PQgetvalue(
res, 0, 8),
"t") == 0;
1700 tableinfo.reloftype = (strcmp(
PQgetvalue(
res, 0, 11),
"") != 0) ?
1709 tableinfo.relam = NULL;
1716 if (tableinfo.relkind == RELKIND_SEQUENCE)
1720 char *footers[2] = {NULL, NULL};
1725 "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n"
1726 " seqstart AS \"%s\",\n"
1727 " seqmin AS \"%s\",\n"
1728 " seqmax AS \"%s\",\n"
1729 " seqincrement AS \"%s\",\n"
1730 " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n"
1731 " seqcache AS \"%s\"\n",
1742 "FROM pg_catalog.pg_sequence\n"
1743 "WHERE seqrelid = '%s';",
1749 "SELECT 'bigint' AS \"%s\",\n"
1750 " start_value AS \"%s\",\n"
1751 " min_value AS \"%s\",\n"
1752 " max_value AS \"%s\",\n"
1753 " increment_by AS \"%s\",\n"
1754 " CASE WHEN is_cycled THEN '%s' ELSE '%s' END AS \"%s\",\n"
1755 " cache_value AS \"%s\"\n",
1776 "\n pg_catalog.quote_ident(relname) || '.' ||"
1777 "\n pg_catalog.quote_ident(attname),"
1779 "\nFROM pg_catalog.pg_class c"
1780 "\nINNER JOIN pg_catalog.pg_depend d ON c.oid=d.refobjid"
1781 "\nINNER JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace"
1782 "\nINNER JOIN pg_catalog.pg_attribute a ON ("
1783 "\n a.attrelid=c.oid AND"
1784 "\n a.attnum=d.refobjsubid)"
1785 "\nWHERE d.classid='pg_catalog.pg_class'::pg_catalog.regclass"
1786 "\n AND d.refclassid='pg_catalog.pg_class'::pg_catalog.regclass"
1787 "\n AND d.objid='%s'"
1788 "\n AND d.deptype IN ('a', 'i')",
1805 footers[0] =
psprintf(
_(
"Owned by: %s"),
1809 footers[0] =
psprintf(
_(
"Sequence for identity column: %s"),
1816 if (tableinfo.relpersistence ==
'u')
1818 schemaname, relationname);
1821 schemaname, relationname);
1837 if (tableinfo.relkind == RELKIND_RELATION ||
1838 tableinfo.relkind == RELKIND_VIEW ||
1839 tableinfo.relkind == RELKIND_MATVIEW ||
1840 tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
1841 tableinfo.relkind == RELKIND_COMPOSITE_TYPE ||
1842 tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
1843 show_column_details =
true;
1855 attname_col = cols++;
1857 atttype_col = cols++;
1859 if (show_column_details)
1863 ",\n (SELECT pg_catalog.pg_get_expr(d.adbin, d.adrelid, true)"
1864 "\n FROM pg_catalog.pg_attrdef d"
1865 "\n WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef)"
1866 ",\n a.attnotnull");
1867 attrdef_col = cols++;
1868 attnotnull_col = cols++;
1870 " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation");
1871 attcoll_col = cols++;
1876 attidentity_col = cols++;
1881 attgenerated_col = cols++;
1883 if (tableinfo.relkind == RELKIND_INDEX ||
1884 tableinfo.relkind == RELKIND_PARTITIONED_INDEX)
1888 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",
1892 isindexkey_col = cols++;
1895 indexdef_col = cols++;
1898 if (tableinfo.relkind == RELKIND_FOREIGN_TABLE)
1901 " '(' || pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(option_name) || ' ' || pg_catalog.quote_literal(option_value) FROM "
1902 " pg_catalog.pg_options_to_table(attfdwoptions)), ', ') || ')' END AS attfdwoptions");
1903 fdwopts_col = cols++;
1908 attstorage_col = cols++;
1913 (tableinfo.relkind == RELKIND_RELATION ||
1914 tableinfo.relkind == RELKIND_PARTITIONED_TABLE ||
1915 tableinfo.relkind == RELKIND_MATVIEW))
1918 attcompression_col = cols++;
1922 if (tableinfo.relkind == RELKIND_RELATION ||
1923 tableinfo.relkind == RELKIND_INDEX ||
1924 tableinfo.relkind == RELKIND_PARTITIONED_INDEX ||
1925 tableinfo.relkind == RELKIND_MATVIEW ||
1926 tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
1927 tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
1929 appendPQExpBufferStr(&
buf,
",\n CASE WHEN a.attstattarget=-1 THEN NULL ELSE a.attstattarget END AS attstattarget");
1930 attstattarget_col = cols++;
1937 if (tableinfo.relkind == RELKIND_RELATION ||
1938 tableinfo.relkind == RELKIND_VIEW ||
1939 tableinfo.relkind == RELKIND_MATVIEW ||
1940 tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
1941 tableinfo.relkind == RELKIND_COMPOSITE_TYPE ||
1942 tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
1945 attdescr_col = cols++;
1950 appendPQExpBuffer(&
buf,
"\nWHERE a.attrelid = '%s' AND a.attnum > 0 AND NOT a.attisdropped", oid);
1959 switch (tableinfo.relkind)
1961 case RELKIND_RELATION:
1962 if (tableinfo.relpersistence ==
'u')
1964 schemaname, relationname);
1967 schemaname, relationname);
1971 schemaname, relationname);
1973 case RELKIND_MATVIEW:
1974 if (tableinfo.relpersistence ==
'u')
1976 schemaname, relationname);
1979 schemaname, relationname);
1982 if (tableinfo.relpersistence ==
'u')
1984 schemaname, relationname);
1987 schemaname, relationname);
1989 case RELKIND_PARTITIONED_INDEX:
1990 if (tableinfo.relpersistence ==
'u')
1992 schemaname, relationname);
1995 schemaname, relationname);
1997 case RELKIND_TOASTVALUE:
1999 schemaname, relationname);
2001 case RELKIND_COMPOSITE_TYPE:
2003 schemaname, relationname);
2005 case RELKIND_FOREIGN_TABLE:
2007 schemaname, relationname);
2009 case RELKIND_PARTITIONED_TABLE:
2010 if (tableinfo.relpersistence ==
'u')
2012 schemaname, relationname);
2015 schemaname, relationname);
2020 tableinfo.relkind, schemaname, relationname);
2028 if (show_column_details)
2034 if (isindexkey_col >= 0)
2036 if (indexdef_col >= 0)
2038 if (fdwopts_col >= 0)
2040 if (attstorage_col >= 0)
2042 if (attcompression_col >= 0)
2044 if (attstattarget_col >= 0)
2046 if (attdescr_col >= 0)
2052 printTableInitialized =
true;
2054 for (
i = 0;
i < cols;
i++)
2058 for (
i = 0;
i < numrows;
i++)
2067 if (show_column_details)
2072 bool mustfree =
false;
2077 strcmp(
PQgetvalue(
res,
i, attnotnull_col),
"t") == 0 ?
"not null" :
"",
2083 if (identity[0] == ATTRIBUTE_IDENTITY_ALWAYS)
2084 default_str =
"generated always as identity";
2085 else if (identity[0] == ATTRIBUTE_IDENTITY_BY_DEFAULT)
2086 default_str =
"generated by default as identity";
2087 else if (generated[0] == ATTRIBUTE_GENERATED_STORED)
2089 default_str =
psprintf(
"generated always as (%s) stored",
2100 if (isindexkey_col >= 0)
2102 if (indexdef_col >= 0)
2106 if (fdwopts_col >= 0)
2110 if (attstorage_col >= 0)
2117 (
storage[0] ==
'x' ?
"extended" :
2118 (
storage[0] ==
'e' ?
"external" :
2124 if (attcompression_col >= 0)
2130 (compression[0] ==
'l' ?
"lz4" :
2131 (compression[0] ==
'\0' ?
"" :
2137 if (attstattarget_col >= 0)
2142 if (attdescr_col >= 0)
2149 if (tableinfo.ispartition)
2155 "SELECT inhparent::pg_catalog.regclass,\n"
2156 " pg_catalog.pg_get_expr(c.relpartbound, c.oid),\n ");
2160 "false as inhdetachpending");
2165 ",\n pg_catalog.pg_get_partition_constraintdef(c.oid)");
2167 "\nFROM pg_catalog.pg_class c"
2168 " JOIN pg_catalog.pg_inherits i"
2169 " ON c.oid = inhrelid"
2170 "\nWHERE c.oid = '%s';", oid);
2177 char *parent_name =
PQgetvalue(result, 0, 0);
2183 strcmp(detached,
"t") == 0 ?
" DETACH PENDING" :
"");
2188 char *partconstraintdef = NULL;
2191 partconstraintdef =
PQgetvalue(result, 0, 3);
2193 if (partconstraintdef == NULL || partconstraintdef[0] ==
'\0')
2204 if (tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
2210 "SELECT pg_catalog.pg_get_partkeydef('%s'::pg_catalog.oid);",
2226 if (tableinfo.relkind == RELKIND_TOASTVALUE)
2232 "SELECT n.nspname, c.relname\n"
2233 "FROM pg_catalog.pg_class c"
2234 " JOIN pg_catalog.pg_namespace n"
2235 " ON n.oid = c.relnamespace\n"
2236 "WHERE reltoastrelid = '%s';", oid);
2253 if (tableinfo.relkind == RELKIND_INDEX ||
2254 tableinfo.relkind == RELKIND_PARTITIONED_INDEX)
2260 "SELECT i.indisunique, i.indisprimary, i.indisclustered, "
2262 " (NOT i.indimmediate) AND "
2263 "EXISTS (SELECT 1 FROM pg_catalog.pg_constraint "
2264 "WHERE conrelid = i.indrelid AND "
2265 "conindid = i.indexrelid AND "
2266 "contype IN ('p','u','x') AND "
2267 "condeferrable) AS condeferrable,\n"
2268 " (NOT i.indimmediate) AND "
2269 "EXISTS (SELECT 1 FROM pg_catalog.pg_constraint "
2270 "WHERE conrelid = i.indrelid AND "
2271 "conindid = i.indexrelid AND "
2272 "contype IN ('p','u','x') AND "
2273 "condeferred) AS condeferred,\n");
2286 "pg_catalog.pg_get_expr(i.indpred, i.indrelid, true)\n"
2287 "FROM pg_catalog.pg_index i, pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_am a\n"
2288 "WHERE i.indexrelid = c.oid AND c.oid = '%s' AND c.relam = a.oid\n"
2289 "AND i.indrelid = c2.oid;",
2302 char *indisunique =
PQgetvalue(result, 0, 0);
2303 char *indisprimary =
PQgetvalue(result, 0, 1);
2304 char *indisclustered =
PQgetvalue(result, 0, 2);
2308 char *indisreplident =
PQgetvalue(result, 0, 6);
2309 char *indnullsnotdistinct =
PQgetvalue(result, 0, 7);
2314 if (strcmp(indisprimary,
"t") == 0)
2316 else if (strcmp(indisunique,
"t") == 0)
2319 if (strcmp(indnullsnotdistinct,
"t") == 0)
2329 schemaname, indtable);
2331 if (strlen(indpred))
2334 if (strcmp(indisclustered,
"t") == 0)
2337 if (strcmp(indisvalid,
"t") != 0)
2340 if (strcmp(deferrable,
"t") == 0)
2343 if (strcmp(deferred,
"t") == 0)
2346 if (strcmp(indisreplident,
"t") == 0)
2354 if (tableinfo.relkind == RELKIND_INDEX)
2356 tableinfo.tablespace,
true);
2362 else if (tableinfo.relkind == RELKIND_RELATION ||
2363 tableinfo.relkind == RELKIND_MATVIEW ||
2364 tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
2365 tableinfo.relkind == RELKIND_PARTITIONED_TABLE ||
2366 tableinfo.relkind == RELKIND_PARTITIONED_INDEX ||
2367 tableinfo.relkind == RELKIND_TOASTVALUE)
2374 if (tableinfo.hasindex)
2377 "SELECT c2.relname, i.indisprimary, i.indisunique, "
2378 "i.indisclustered, i.indisvalid, "
2379 "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n "
2380 "pg_catalog.pg_get_constraintdef(con.oid, true), "
2381 "contype, condeferrable, condeferred");
2388 "\nFROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i\n"
2389 " LEFT JOIN pg_catalog.pg_constraint con ON (conrelid = i.indrelid AND conindid = i.indexrelid AND contype IN ('p','u','x'))\n"
2390 "WHERE c.oid = '%s' AND c.oid = i.indrelid AND i.indexrelid = c2.oid\n"
2391 "ORDER BY i.indisprimary DESC, c2.relname;",
2402 for (
i = 0;
i < tuples;
i++)
2416 const char *indexdef;
2417 const char *usingpos;
2422 else if (strcmp(
PQgetvalue(result,
i, 2),
"t") == 0)
2432 usingpos = strstr(indexdef,
" USING ");
2434 indexdef = usingpos + 7;
2467 if (tableinfo.checks)
2470 "SELECT r.conname, "
2471 "pg_catalog.pg_get_constraintdef(r.oid, true)\n"
2472 "FROM pg_catalog.pg_constraint r\n"
2473 "WHERE r.conrelid = '%s' AND r.contype = 'c'\n"
2485 for (
i = 0;
i < tuples;
i++)
2503 if (tableinfo.hastriggers ||
2504 tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
2507 (tableinfo.ispartition || tableinfo.relkind == RELKIND_PARTITIONED_TABLE))
2514 "SELECT conrelid = '%s'::pg_catalog.regclass AS sametable,\n"
2516 " pg_catalog.pg_get_constraintdef(oid, true) AS condef,\n"
2517 " conrelid::pg_catalog.regclass AS ontable\n"
2518 " FROM pg_catalog.pg_constraint,\n"
2519 " pg_catalog.pg_partition_ancestors('%s')\n"
2520 " WHERE conrelid = relid AND contype = 'f' AND conparentid = 0\n"
2521 "ORDER BY sametable DESC, conname;",
2527 "SELECT true as sametable, conname,\n"
2528 " pg_catalog.pg_get_constraintdef(r.oid, true) as condef,\n"
2529 " conrelid::pg_catalog.regclass AS ontable\n"
2530 "FROM pg_catalog.pg_constraint r\n"
2531 "WHERE r.conrelid = '%s' AND r.contype = 'f'\n",
2547 int i_sametable =
PQfnumber(result,
"sametable"),
2548 i_conname =
PQfnumber(result,
"conname"),
2550 i_ontable =
PQfnumber(result,
"ontable");
2553 for (
i = 0;
i < tuples;
i++)
2560 if (strcmp(
PQgetvalue(result,
i, i_sametable),
"f") == 0)
2577 if (tableinfo.hastriggers ||
2578 tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
2583 "SELECT conname, conrelid::pg_catalog.regclass AS ontable,\n"
2584 " pg_catalog.pg_get_constraintdef(oid, true) AS condef\n"
2585 " FROM pg_catalog.pg_constraint c\n"
2586 " WHERE confrelid IN (SELECT pg_catalog.pg_partition_ancestors('%s')\n"
2587 " UNION ALL VALUES ('%s'::pg_catalog.regclass))\n"
2588 " AND contype = 'f' AND conparentid = 0\n"
2589 "ORDER BY conname;",
2595 "SELECT conname, conrelid::pg_catalog.regclass AS ontable,\n"
2596 " pg_catalog.pg_get_constraintdef(oid, true) AS condef\n"
2597 " FROM pg_catalog.pg_constraint\n"
2598 " WHERE confrelid = %s AND contype = 'f'\n"
2599 "ORDER BY conname;",
2611 int i_conname =
PQfnumber(result,
"conname"),
2612 i_ontable =
PQfnumber(result,
"ontable"),
2616 for (
i = 0;
i < tuples;
i++)
2635 " pol.polpermissive,\n");
2638 " 't' as polpermissive,\n");
2640 " 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"
2641 " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n"
2642 " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n"
2643 " CASE pol.polcmd\n"
2644 " WHEN 'r' THEN 'SELECT'\n"
2645 " WHEN 'a' THEN 'INSERT'\n"
2646 " WHEN 'w' THEN 'UPDATE'\n"
2647 " WHEN 'd' THEN 'DELETE'\n"
2649 "FROM pg_catalog.pg_policy pol\n"
2650 "WHERE pol.polrelid = '%s' ORDER BY 1;",
2664 if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0)
2667 if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0)
2670 if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0)
2673 if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0)
2676 if (!tableinfo.rowsecurity && tuples > 0)
2680 for (
i = 0;
i < tuples;
i++)
2716 "stxrelid::pg_catalog.regclass, "
2717 "stxnamespace::pg_catalog.regnamespace::pg_catalog.text AS nsp, "
2719 "pg_catalog.pg_get_statisticsobjdef_columns(oid) AS columns,\n"
2720 " 'd' = any(stxkind) AS ndist_enabled,\n"
2721 " 'f' = any(stxkind) AS deps_enabled,\n"
2722 " 'm' = any(stxkind) AS mcv_enabled,\n"
2724 "FROM pg_catalog.pg_statistic_ext\n"
2725 "WHERE stxrelid = '%s'\n"
2726 "ORDER BY nsp, stxname;",
2739 for (
i = 0;
i < tuples;
i++)
2741 bool gotone =
false;
2743 bool has_dependencies;
2748 has_ndistinct = (strcmp(
PQgetvalue(result,
i, 5),
"t") == 0);
2749 has_dependencies = (strcmp(
PQgetvalue(result,
i, 6),
"t") == 0);
2750 has_mcv = (strcmp(
PQgetvalue(result,
i, 7),
"t") == 0);
2767 has_all = (has_ndistinct && has_dependencies && has_mcv);
2768 has_some = (has_ndistinct || has_dependencies || has_mcv);
2770 if (has_some && !has_all)
2781 if (has_dependencies)
2813 "stxrelid::pg_catalog.regclass, "
2814 "stxnamespace::pg_catalog.regnamespace AS nsp, "
2816 " (SELECT pg_catalog.string_agg(pg_catalog.quote_ident(attname),', ')\n"
2817 " FROM pg_catalog.unnest(stxkeys) s(attnum)\n"
2818 " JOIN pg_catalog.pg_attribute a ON (stxrelid = a.attrelid AND\n"
2819 " a.attnum = s.attnum AND NOT attisdropped)) AS columns,\n"
2820 " 'd' = any(stxkind) AS ndist_enabled,\n"
2821 " 'f' = any(stxkind) AS deps_enabled,\n"
2822 " 'm' = any(stxkind) AS mcv_enabled,\n");
2829 "WHERE stxrelid = '%s'\n"
2843 for (
i = 0;
i < tuples;
i++)
2845 bool gotone =
false;
2888 if (tableinfo.hasrules && tableinfo.relkind != RELKIND_MATVIEW)
2891 "SELECT r.rulename, trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true)), "
2893 "FROM pg_catalog.pg_rewrite r\n"
2894 "WHERE r.ev_class = '%s' ORDER BY 1;",
2907 for (category = 0; category < 4; category++)
2909 have_heading =
false;
2911 for (
i = 0;
i < tuples;
i++)
2913 const char *ruledef;
2914 bool list_rule =
false;
2956 have_heading =
true;
2979 "FROM pg_catalog.pg_publication p\n"
2980 " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n"
2981 " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n"
2982 "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n"
2985 " , pg_get_expr(pr.prqual, c.oid)\n"
2986 " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n"
2987 " (SELECT string_agg(attname, ', ')\n"
2988 " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n"
2989 " pg_catalog.pg_attribute\n"
2990 " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n"
2992 "FROM pg_catalog.pg_publication p\n"
2993 " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n"
2994 " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n"
2995 "WHERE pr.prrelid = '%s'\n"
3000 "FROM pg_catalog.pg_publication p\n"
3001 "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n"
3003 oid, oid, oid, oid);
3011 "FROM pg_catalog.pg_publication p\n"
3012 "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n"
3013 "WHERE pr.prrelid = '%s'\n"
3018 "FROM pg_catalog.pg_publication p\n"
3019 "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n"
3034 for (
i = 0;
i < tuples;
i++)
3058 "SELECT co.conname, at.attname, co.connoinherit, co.conislocal,\n"
3059 "co.coninhcount <> 0\n"
3060 "FROM pg_catalog.pg_constraint co JOIN\n"
3061 "pg_catalog.pg_attribute at ON\n"
3062 "(at.attnum = co.conkey[1])\n"
3063 "WHERE co.contype = 'n' AND\n"
3064 "co.conrelid = '%s'::pg_catalog.regclass AND\n"
3065 "at.attrelid = '%s'::pg_catalog.regclass\n"
3066 "ORDER BY at.attnum",
3080 for (
i = 0;
i < tuples;
i++)
3082 bool islocal =
PQgetvalue(result,
i, 3)[0] ==
't';
3083 bool inherited =
PQgetvalue(result,
i, 4)[0] ==
't';
3090 islocal && inherited ?
_(
" (local, inherited)") :
3091 inherited ?
_(
" (inherited)") :
"");
3100 if ((tableinfo.relkind == RELKIND_VIEW ||
3101 tableinfo.relkind == RELKIND_MATVIEW) &&
verbose)
3106 "SELECT pg_catalog.pg_get_viewdef('%s'::pg_catalog.oid, true);",
3127 if (tableinfo.hasrules)
3130 "SELECT r.rulename, trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true))\n"
3131 "FROM pg_catalog.pg_rewrite r\n"
3132 "WHERE r.ev_class = '%s' AND r.rulename != '_RETURN' ORDER BY 1;",
3143 const char *ruledef;
3161 if (tableinfo.hastriggers)
3168 "pg_catalog.pg_get_triggerdef(t.oid, true), "
3169 "t.tgenabled, t.tgisinternal,\n");
3187 " CASE WHEN t.tgparentid != 0 THEN\n"
3188 " (SELECT u.tgrelid::pg_catalog.regclass\n"
3189 " FROM pg_catalog.pg_trigger AS u,\n"
3190 " pg_catalog.pg_partition_ancestors(t.tgrelid) WITH ORDINALITY AS a(relid, depth)\n"
3191 " WHERE u.tgname = t.tgname AND u.tgrelid = a.relid\n"
3192 " AND u.tgparentid = 0\n"
3193 " ORDER BY a.depth LIMIT 1)\n"
3194 " END AS parent\n");
3199 "FROM pg_catalog.pg_trigger t\n"
3200 "WHERE t.tgrelid = '%s' AND ",
3212 " OR EXISTS (SELECT 1 FROM pg_catalog.pg_depend WHERE objid = t.oid \n"
3213 " AND refclassid = 'pg_catalog.pg_trigger'::pg_catalog.regclass))");
3235 for (category = 0; category <= 4; category++)
3237 have_heading =
false;
3238 for (
i = 0;
i < tuples;
i++)
3242 const char *usingpos;
3243 const char *tgenabled;
3244 const char *tgisinternal;
3251 list_trigger =
false;
3255 if (*tgenabled ==
'O' || *tgenabled ==
't')
3256 list_trigger =
true;
3259 if ((*tgenabled ==
'D' || *tgenabled ==
'f') &&
3260 *tgisinternal ==
'f')
3261 list_trigger =
true;
3264 if ((*tgenabled ==
'D' || *tgenabled ==
'f') &&
3265 *tgisinternal ==
't')
3266 list_trigger =
true;
3269 if (*tgenabled ==
'A')
3270 list_trigger =
true;
3273 if (*tgenabled ==
'R')
3274 list_trigger =
true;
3277 if (list_trigger ==
false)
3281 if (have_heading ==
false)
3302 have_heading =
true;
3307 usingpos = strstr(tgdef,
" TRIGGER ");
3309 tgdef = usingpos + 9;
3328 if (tableinfo.relkind == RELKIND_RELATION ||
3329 tableinfo.relkind == RELKIND_MATVIEW ||
3330 tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
3331 tableinfo.relkind == RELKIND_PARTITIONED_TABLE ||
3332 tableinfo.relkind == RELKIND_PARTITIONED_INDEX ||
3333 tableinfo.relkind == RELKIND_TOASTVALUE)
3335 bool is_partitioned;
3340 is_partitioned = (tableinfo.relkind == RELKIND_PARTITIONED_TABLE ||
3341 tableinfo.relkind == RELKIND_PARTITIONED_INDEX);
3344 if (tableinfo.relkind == RELKIND_FOREIGN_TABLE)
3350 "SELECT s.srvname,\n"
3351 " pg_catalog.array_to_string(ARRAY(\n"
3352 " SELECT pg_catalog.quote_ident(option_name)"
3353 " || ' ' || pg_catalog.quote_literal(option_value)\n"
3354 " FROM pg_catalog.pg_options_to_table(ftoptions)), ', ')\n"
3355 "FROM pg_catalog.pg_foreign_table f,\n"
3356 " pg_catalog.pg_foreign_server s\n"
3357 "WHERE f.ftrelid = '%s' AND s.oid = f.ftserver;",
3375 if (ftoptions && ftoptions[0] !=
'\0')
3385 "SELECT c.oid::pg_catalog.regclass\n"
3386 "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n"
3387 "WHERE c.oid = i.inhparent AND i.inhrelid = '%s'\n"
3388 " AND c.relkind != " CppAsString2(RELKIND_PARTITIONED_TABLE)
3389 " AND c.relkind != " CppAsString2(RELKIND_PARTITIONED_INDEX)
3390 "\nORDER BY inhseqno;",
3398 const char *s =
_(
"Inherits");
3403 for (
i = 0;
i < tuples;
i++)
3423 "SELECT c.oid::pg_catalog.regclass, c.relkind,"
3424 " inhdetachpending,"
3425 " pg_catalog.pg_get_expr(c.relpartbound, c.oid)\n"
3426 "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n"
3427 "WHERE c.oid = i.inhrelid AND i.inhparent = '%s'\n"
3428 "ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT',"
3429 " c.oid::pg_catalog.regclass::pg_catalog.text;",
3433 "SELECT c.oid::pg_catalog.regclass, c.relkind,"
3434 " false AS inhdetachpending,"
3435 " pg_catalog.pg_get_expr(c.relpartbound, c.oid)\n"
3436 "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n"
3437 "WHERE c.oid = i.inhrelid AND i.inhparent = '%s'\n"
3438 "ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT',"
3439 " c.oid::pg_catalog.regclass::pg_catalog.text;",
3443 "SELECT c.oid::pg_catalog.regclass, c.relkind,"
3444 " false AS inhdetachpending, NULL\n"
3445 "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n"
3446 "WHERE c.oid = i.inhrelid AND i.inhparent = '%s'\n"
3447 "ORDER BY c.oid::pg_catalog.regclass::pg_catalog.text;",
3461 if (is_partitioned && tuples == 0)
3481 const char *ct = is_partitioned ?
_(
"Partitions") :
_(
"Child tables");
3484 for (
i = 0;
i < tuples;
i++)
3496 if (child_relkind == RELKIND_PARTITIONED_TABLE ||
3497 child_relkind == RELKIND_PARTITIONED_INDEX)
3499 else if (child_relkind == RELKIND_FOREIGN_TABLE)
3512 if (tableinfo.reloftype)
3519 (tableinfo.relkind == RELKIND_RELATION ||
3520 tableinfo.relkind == RELKIND_MATVIEW) &&
3526 tableinfo.relreplident !=
'i' &&
3527 ((strcmp(schemaname,
"pg_catalog") != 0 && tableinfo.relreplident !=
'd') ||
3528 (strcmp(schemaname,
"pg_catalog") == 0 && tableinfo.relreplident !=
'n')))
3530 const char *s =
_(
"Replica Identity");
3534 tableinfo.relreplident ==
'f' ?
"FULL" :
3535 tableinfo.relreplident ==
'n' ?
"NOTHING" :
3542 if (
verbose && tableinfo.relkind != RELKIND_MATVIEW && tableinfo.hasoids)
3559 tableinfo.reloptions && tableinfo.reloptions[0] !=
'\0')
3561 const char *t =
_(
"Options");
3574 if (printTableInitialized)
3597 if (relkind == RELKIND_RELATION ||
3598 relkind == RELKIND_MATVIEW ||
3599 relkind == RELKIND_INDEX ||
3600 relkind == RELKIND_PARTITIONED_TABLE ||
3601 relkind == RELKIND_PARTITIONED_INDEX ||
3602 relkind == RELKIND_TOASTVALUE)
3615 "SELECT spcname FROM pg_catalog.pg_tablespace\n"
3668 const char align =
'l';
3676 "SELECT r.rolname, r.rolsuper, r.rolinherit,\n"
3677 " r.rolcreaterole, r.rolcreatedb, r.rolcanlogin,\n"
3678 " r.rolconnlimit, r.rolvaliduntil");
3694 if (!showSystem && !pattern)
3698 NULL,
"r.rolname", NULL, NULL,
3712 attr =
pg_malloc0((nrows + 1) *
sizeof(*attr));
3722 for (
i = 0;
i < nrows;
i++)
3784 for (
i = 0;
i < nrows;
i++)
3815 "pg_catalog.array_to_string(setconfig, E'\\n') AS \"%s\"\n"
3816 "FROM pg_catalog.pg_db_role_setting s\n"
3817 "LEFT JOIN pg_catalog.pg_database d ON d.oid = setdatabase\n"
3818 "LEFT JOIN pg_catalog.pg_roles r ON r.oid = setrole\n",
3823 NULL,
"r.rolname", NULL, NULL, &havewhere, 1))
3826 NULL,
"d.datname", NULL, NULL,
3844 if (pattern && pattern2)
3845 pg_log_error(
"Did not find any settings for role \"%s\" and database \"%s\".",
3848 pg_log_error(
"Did not find any settings for role \"%s\".",
3856 myopt.
title =
_(
"List of settings");
3883 "SELECT m.rolname AS \"%s\", r.rolname AS \"%s\",\n"
3884 " pg_catalog.concat_ws(', ',\n",
3890 " CASE WHEN pam.admin_option THEN 'ADMIN' END,\n"
3891 " CASE WHEN pam.inherit_option THEN 'INHERIT' END,\n"
3892 " CASE WHEN pam.set_option THEN 'SET' END\n");
3895 " CASE WHEN pam.admin_option THEN 'ADMIN' END,\n"
3896 " CASE WHEN m.rolinherit THEN 'INHERIT' END,\n"
3901 " g.rolname AS \"%s\"\n",
3906 "FROM pg_catalog.pg_roles m\n"
3907 " JOIN pg_catalog.pg_auth_members pam ON (pam.member = m.oid)\n"
3908 " LEFT JOIN pg_catalog.pg_roles r ON (pam.roleid = r.oid)\n"
3909 " LEFT JOIN pg_catalog.pg_roles g ON (pam.grantor = g.oid)\n");
3911 if (!showSystem && !pattern)
3915 NULL,
"m.rolname", NULL, NULL,
3930 myopt.
title =
_(
"List of role grants");
3957 bool showTables = strchr(tabtypes,
't') != NULL;
3958 bool showIndexes = strchr(tabtypes,
'i') != NULL;
3959 bool showViews = strchr(tabtypes,
'v') != NULL;
3960 bool showMatViews = strchr(tabtypes,
'm') != NULL;
3961 bool showSeq = strchr(tabtypes,
's') != NULL;
3962 bool showForeign = strchr(tabtypes,
'E') != NULL;
3968 bool translate_columns[] = {
false,
false,
true,
false,
false,
false,
false,
false,
false};
3971 if (!(showTables || showIndexes || showViews || showMatViews || showSeq || showForeign))
3972 showTables = showViews = showMatViews = showSeq = showForeign =
true;
3977 "SELECT n.nspname as \"%s\",\n"
3978 " c.relname as \"%s\",\n"
3986 " WHEN " CppAsString2(RELKIND_FOREIGN_TABLE)
" THEN '%s'"
3987 " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE)
" THEN '%s'"
3988 " WHEN " CppAsString2(RELKIND_PARTITIONED_INDEX)
" THEN '%s'"
3990 " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
4009 ",\n c2.relname as \"%s\"",
4020 ",\n CASE c.relpersistence WHEN 'p' THEN '%s' WHEN 't' THEN '%s' WHEN 'u' THEN '%s' END as \"%s\"",
4025 translate_columns[cols_so_far] =
true;
4037 (showTables || showMatViews || showIndexes))
4039 ",\n am.amname as \"%s\"",
4043 ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_table_size(c.oid)) as \"%s\""
4044 ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
4050 "\nFROM pg_catalog.pg_class c"
4051 "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
4054 (showTables || showMatViews || showIndexes))
4056 "\n LEFT JOIN pg_catalog.pg_am am ON am.oid = c.relam");
4060 "\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
4061 "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
4069 if (showSystem || pattern)
4081 if (showSystem || pattern)
4089 if (!showSystem && !pattern)
4091 " AND n.nspname !~ '^pg_toast'\n"
4092 " AND n.nspname <> 'information_schema'\n");
4095 "n.nspname",
"c.relname", NULL,
4096 "pg_catalog.pg_table_is_visible(c.oid)",
4118 pg_log_error(
"Did not find any relation named \"%s\".",
4126 myopt.
title =
_(
"List of relations");
4156 bool showTables = strchr(reltypes,
't') != NULL;
4157 bool showIndexes = strchr(reltypes,
'i') != NULL;
4158 bool showNested = strchr(reltypes,
'n') != NULL;
4163 bool translate_columns[] = {
false,
false,
false,
false,
false,
false,
false,
false,
false};
4164 const char *tabletitle;
4165 bool mixed_output =
false;
4174 pg_log_error(
"The server (version %s) does not support declarative table partitioning.",
4176 sverbuf,
sizeof(sverbuf)));
4181 if (!showTables && !showIndexes)
4182 showTables = showIndexes =
true;
4184 if (showIndexes && !showTables)
4185 tabletitle =
_(
"List of partitioned indexes");
4186 else if (showTables && !showIndexes)
4187 tabletitle =
_(
"List of partitioned tables");
4191 tabletitle =
_(
"List of partitioned relations");
4192 mixed_output =
true;
4198 "SELECT n.nspname as \"%s\",\n"
4199 " c.relname as \"%s\",\n"
4200 " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
4208 ",\n CASE c.relkind"
4209 " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE)
" THEN '%s'"
4210 " WHEN " CppAsString2(RELKIND_PARTITIONED_INDEX)
" THEN '%s'"
4216 translate_columns[3] =
true;
4219 if (showNested || pattern)
4221 ",\n inh.inhparent::pg_catalog.regclass as \"%s\"",
4226 ",\n c2.oid::pg_catalog.regclass as \"%s\"",
4234 ",\n s.dps as \"%s\"",
4237 ",\n s.tps as \"%s\"",
4243 ",\n s.tps as \"%s\"",
4247 ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
4252 "\nFROM pg_catalog.pg_class c"
4253 "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
4257 "\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
4258 "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
4260 if (showNested || pattern)
4262 "\n LEFT JOIN pg_catalog.pg_inherits inh ON c.oid = inh.inhrelid");
4269 ",\n LATERAL (WITH RECURSIVE d\n"
4270 " AS (SELECT inhrelid AS oid, 1 AS level\n"
4271 " FROM pg_catalog.pg_inherits\n"
4272 " WHERE inhparent = c.oid\n"
4274 " SELECT inhrelid, level + 1\n"
4275 " FROM pg_catalog.pg_inherits i\n"
4276 " JOIN d ON i.inhparent = d.oid)\n"
4277 " SELECT pg_catalog.pg_size_pretty(sum(pg_catalog.pg_table_size("
4278 "d.oid))) AS tps,\n"
4279 " pg_catalog.pg_size_pretty(sum("
4280 "\n CASE WHEN d.level = 1"
4281 " THEN pg_catalog.pg_table_size(d.oid) ELSE 0 END)) AS dps\n"
4288 ",\n LATERAL (SELECT pg_catalog.pg_size_pretty(sum("
4289 "\n CASE WHEN ppt.isleaf AND ppt.level = 1"
4290 "\n THEN pg_catalog.pg_table_size(ppt.relid)"
4291 " ELSE 0 END)) AS dps"
4292 ",\n pg_catalog.pg_size_pretty(sum("
4293 "pg_catalog.pg_table_size(ppt.relid))) AS tps"
4294 "\n FROM pg_catalog.pg_partition_tree(c.oid) ppt) s");
4307 " AND NOT c.relispartition\n" :
"");
4311 " AND n.nspname !~ '^pg_toast'\n"
4312 " AND n.nspname <> 'information_schema'\n");
4315 "n.nspname",
"c.relname", NULL,
4316 "pg_catalog.pg_table_is_visible(c.oid)",
4324 mixed_output ?
"\"Type\" DESC, " :
"",
4325 showNested || pattern ?
"\"Parent name\" NULLS FIRST, " :
"");
4364 "SELECT l.lanname AS \"%s\",\n"
4365 " pg_catalog.pg_get_userbyid(l.lanowner) as \"%s\",\n"
4366 " l.lanpltrusted AS \"%s\"",
4374 ",\n NOT l.lanispl AS \"%s\",\n"
4375 " l.lanplcallfoid::pg_catalog.regprocedure AS \"%s\",\n"
4376 " l.lanvalidator::pg_catalog.regprocedure AS \"%s\",\n "
4377 "l.laninline::pg_catalog.regprocedure AS \"%s\",\n ",
4386 ",\n d.description AS \"%s\""
4387 "\nFROM pg_catalog.pg_language l\n"
4388 "LEFT JOIN pg_catalog.pg_description d\n"
4389 " ON d.classoid = l.tableoid AND d.objoid = l.oid\n"
4390 " AND d.objsubid = 0\n",
4396 NULL,
"l.lanname", NULL, NULL,
4404 if (!showSystem && !pattern)
4416 myopt.
title =
_(
"List of languages");
4441 "SELECT n.nspname as \"%s\",\n"
4442 " t.typname as \"%s\",\n"
4443 " pg_catalog.format_type(t.typbasetype, t.typtypmod) as \"%s\",\n"
4444 " (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type bt\n"
4445 " WHERE c.oid = t.typcollation AND bt.oid = t.typbasetype AND t.typcollation <> bt.typcollation) as \"%s\",\n"
4446 " CASE WHEN t.typnotnull THEN 'not null' END as \"%s\",\n"
4447 " t.typdefault as \"%s\",\n"
4448 " pg_catalog.array_to_string(ARRAY(\n"
4449 " SELECT pg_catalog.pg_get_constraintdef(r.oid, true) FROM pg_catalog.pg_constraint r WHERE t.oid = r.contypid\n"
4450 " ), ' ') as \"%s\"",
4464 ",\n d.description as \"%s\"",
4469 "\nFROM pg_catalog.pg_type t\n"
4470 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
4474 " LEFT JOIN pg_catalog.pg_description d "
4475 "ON d.classoid = t.tableoid AND d.objoid = t.oid "
4476 "AND d.objsubid = 0\n");
4480 if (!showSystem && !pattern)
4482 " AND n.nspname <> 'information_schema'\n");
4485 "n.nspname",
"t.typname", NULL,
4486 "pg_catalog.pg_type_is_visible(t.oid)",
4501 myopt.
title =
_(
"List of domains");
4521 static const bool translate_columns[] =
4522 {
false,
false,
false,
false,
true,
false};
4527 "SELECT n.nspname AS \"%s\",\n"
4528 " c.conname AS \"%s\",\n"
4529 " pg_catalog.pg_encoding_to_char(c.conforencoding) AS \"%s\",\n"
4530 " pg_catalog.pg_encoding_to_char(c.contoencoding) AS \"%s\",\n"
4531 " CASE WHEN c.condefault THEN '%s'\n"
4532 " ELSE '%s' END AS \"%s\"",
4542 ",\n d.description AS \"%s\"",
4546 "\nFROM pg_catalog.pg_conversion c\n"
4547 " JOIN pg_catalog.pg_namespace n "
4548 "ON n.oid = c.connamespace\n");
4552 "LEFT JOIN pg_catalog.pg_description d "
4553 "ON d.classoid = c.tableoid\n"
4554 " AND d.objoid = c.oid "
4555 "AND d.objsubid = 0\n");
4559 if (!showSystem && !pattern)
4561 " AND n.nspname <> 'information_schema'\n");
4564 "n.nspname",
"c.conname", NULL,
4565 "pg_catalog.pg_conversion_is_visible(c.oid)",
4580 myopt.
title =
_(
"List of conversions");
4606 "SELECT s.name AS \"%s\", "
4607 "pg_catalog.current_setting(s.name) AS \"%s\"",
4614 ", s.vartype AS \"%s\", s.context AS \"%s\", ",
4628 " LEFT JOIN pg_catalog.pg_parameter_acl p\n"
4629 " ON pg_catalog.lower(s.name) = p.parname\n");
4634 NULL,
"pg_catalog.lower(s.name)", NULL,
4638 " s.setting IS DISTINCT FROM s.boot_val\n");
4649 myopt.
title =
_(
"List of configuration parameters");
4651 myopt.
title =
_(
"List of non-default configuration parameters");
4671 static const bool translate_columns[] =
4672 {
false,
false,
false,
true,
false,
false,
false};
4678 pg_log_error(
"The server (version %s) does not support event triggers.",
4680 sverbuf,
sizeof(sverbuf)));
4687 "SELECT evtname as \"%s\", "
4688 "evtevent as \"%s\", "
4689 "pg_catalog.pg_get_userbyid(e.evtowner) as \"%s\",\n"
4690 " case evtenabled when 'O' then '%s'"
4691 " when 'R' then '%s'"
4692 " when 'A' then '%s'"
4693 " when 'D' then '%s' end as \"%s\",\n"
4694 " e.evtfoid::pg_catalog.regproc as \"%s\", "
4695 "pg_catalog.array_to_string(array(select x"
4696 " from pg_catalog.unnest(evttags) as t(x)), ', ') as \"%s\"",
4709 ",\npg_catalog.obj_description(e.oid, 'pg_event_trigger') as \"%s\"",
4712 "\nFROM pg_catalog.pg_event_trigger e ");
4715 NULL,
"evtname", NULL, NULL,
4730 myopt.
title =
_(
"List of event triggers");
4757 pg_log_error(
"The server (version %s) does not support extended statistics.",
4759 sverbuf,
sizeof(sverbuf)));
4766 "es.stxnamespace::pg_catalog.regnamespace::pg_catalog.text AS \"%s\", \n"
4767 "es.stxname AS \"%s\", \n",
4773 "pg_catalog.format('%%s FROM %%s', \n"
4774 " pg_catalog.pg_get_statisticsobjdef_columns(es.oid), \n"
4775 " es.stxrelid::pg_catalog.regclass) AS \"%s\"",
4779 "pg_catalog.format('%%s FROM %%s', \n"
4780 " (SELECT pg_catalog.string_agg(pg_catalog.quote_ident(a.attname),', ') \n"
4781 " FROM pg_catalog.unnest(es.stxkeys) s(attnum) \n"
4782 " JOIN pg_catalog.pg_attribute a \n"
4783 " ON (es.stxrelid = a.attrelid \n"
4784 " AND a.attnum = s.attnum \n"
4785 " AND NOT a.attisdropped)), \n"
4786 "es.stxrelid::pg_catalog.regclass) AS \"%s\"",
4790 ",\nCASE WHEN 'd' = any(es.stxkind) THEN 'defined' \n"
4792 "CASE WHEN 'f' = any(es.stxkind) THEN 'defined' \n"
4803 ",\nCASE WHEN 'm' = any(es.stxkind) THEN 'defined' \n"
4809 " \nFROM pg_catalog.pg_statistic_ext es \n");
4813 "es.stxnamespace::pg_catalog.regnamespace::pg_catalog.text",
"es.stxname",
4814 NULL,
"pg_catalog.pg_statistics_obj_is_visible(es.oid)",
4829 myopt.
title =
_(
"List of extended statistics");
4849 static const bool translate_columns[] = {
false,
false,
false,
true,
false};
4854 "SELECT pg_catalog.format_type(castsource, NULL) AS \"%s\",\n"
4855 " pg_catalog.format_type(casttarget, NULL) AS \"%s\",\n",
4865 " CASE WHEN c.castmethod = '%c' THEN '(binary coercible)'\n"
4866 " WHEN c.castmethod = '%c' THEN '(with inout)'\n"
4868 " END AS \"%s\",\n",
4869 COERCION_METHOD_BINARY,
4870 COERCION_METHOD_INOUT,
4874 " CASE WHEN c.castcontext = '%c' THEN '%s'\n"
4875 " WHEN c.castcontext = '%c' THEN '%s'\n"
4878 COERCION_CODE_EXPLICIT,
4880 COERCION_CODE_ASSIGNMENT,
4887 ",\n d.description AS \"%s\"",
4895 "\nFROM pg_catalog.pg_cast c LEFT JOIN pg_catalog.pg_proc p\n"
4896 " ON c.castfunc = p.oid\n"
4897 " LEFT JOIN pg_catalog.pg_type ts\n"
4898 " ON c.castsource = ts.oid\n"
4899 " LEFT JOIN pg_catalog.pg_namespace ns\n"
4900 " ON ns.oid = ts.typnamespace\n"
4901 " LEFT JOIN pg_catalog.pg_type tt\n"
4902 " ON c.casttarget = tt.oid\n"
4903 " LEFT JOIN pg_catalog.pg_namespace nt\n"
4904 " ON nt.oid = tt.typnamespace\n");
4908 " LEFT JOIN pg_catalog.pg_description d\n"
4909 " ON d.classoid = c.tableoid AND d.objoid = "
4910 "c.oid AND d.objsubid = 0\n");
4919 "ns.nspname",
"ts.typname",
4920 "pg_catalog.format_type(ts.oid, NULL)",
4921 "pg_catalog.pg_type_is_visible(ts.oid)",
4928 "nt.nspname",
"tt.typname",
4929 "pg_catalog.format_type(tt.oid, NULL)",
4930 "pg_catalog.pg_type_is_visible(tt.oid)",
4942 myopt.
title =
_(
"List of casts");
4968 static const bool translate_columns[] = {
false,
false,
false,
false,
false,
false,
false,
true,
false};
4974 " n.nspname AS \"%s\",\n"
4975 " c.collname AS \"%s\",\n",
4981 " CASE c.collprovider WHEN 'd' THEN 'default' WHEN 'c' THEN 'libc' WHEN 'i' THEN 'icu' END AS \"%s\",\n",
4985 " 'libc' AS \"%s\",\n",
4989 " c.collcollate AS \"%s\",\n"
4990 " c.collctype AS \"%s\",\n",
4996 " c.colliculocale AS \"%s\",\n",
5000 " c.collcollate AS \"%s\",\n",
5005 " c.collicurules AS \"%s\",\n",
5009 " NULL AS \"%s\",\n",
5014 " CASE WHEN c.collisdeterministic THEN '%s' ELSE '%s' END AS \"%s\"",
5025 ",\n pg_catalog.obj_description(c.oid, 'pg_collation') AS \"%s\"",
5029 "\nFROM pg_catalog.pg_collation c, pg_catalog.pg_namespace n\n"
5030 "WHERE n.oid = c.collnamespace\n");
5032 if (!showSystem && !pattern)
5034 " AND n.nspname <> 'information_schema'\n");
5042 appendPQExpBufferStr(&
buf,
" AND c.collencoding IN (-1, pg_catalog.pg_char_to_encoding(pg_catalog.getdatabaseencoding()))\n");
5045 "n.nspname",
"c.collname", NULL,
5046 "pg_catalog.pg_collation_is_visible(c.oid)",
5061 myopt.
title =
_(
"List of collations");
5083 int pub_schema_tuples = 0;
5084 char **footers = NULL;
5088 "SELECT n.nspname AS \"%s\",\n"
5089 " pg_catalog.pg_get_userbyid(n.nspowner) AS \"%s\"",
5098 ",\n pg_catalog.obj_description(n.oid, 'pg_namespace') AS \"%s\"",
5103 "\nFROM pg_catalog.pg_namespace n\n");
5105 if (!showSystem && !pattern)
5107 "WHERE n.nspname !~ '^pg_' AND n.nspname <> 'information_schema'\n");
5110 !showSystem && !pattern,
false,
5111 NULL,
"n.nspname", NULL,
5123 myopt.
title =
_(
"List of schemas");
5133 "FROM pg_catalog.pg_publication p\n"
5134 " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n"
5135 " JOIN pg_catalog.pg_namespace n ON n.oid = pn.pnnspid \n"
5136 "WHERE n.nspname = '%s'\n"
5145 if (pub_schema_tuples > 0)
5152 footers = (
char **)
pg_malloc((1 + pub_schema_tuples + 1) *
sizeof(
char *));
5156 for (
i = 0;
i < pub_schema_tuples;
i++)