18 #include "catalog/pg_am_d.h"
19 #include "catalog/pg_amop_d.h"
20 #include "catalog/pg_attribute_d.h"
21 #include "catalog/pg_cast_d.h"
22 #include "catalog/pg_class_d.h"
23 #include "catalog/pg_collation_d.h"
24 #include "catalog/pg_constraint_d.h"
25 #include "catalog/pg_default_acl_d.h"
26 #include "catalog/pg_proc_d.h"
27 #include "catalog/pg_statistic_ext_d.h"
28 #include "catalog/pg_subscription_d.h"
29 #include "catalog/pg_type_d.h"
40 const char *relationname,
52 const char *pnspname,
const char *prsname);
56 bool have_where,
bool force_escape,
57 const char *schemavar,
const char *namevar,
58 const char *altnamevar,
59 const char *visibilityrule,
60 bool *added_clause,
int maxparts);
86 "SELECT n.nspname as \"%s\",\n"
87 " p.proname AS \"%s\",\n"
88 " pg_catalog.format_type(p.prorettype, NULL) AS \"%s\",\n"
89 " CASE WHEN p.pronargs = 0\n"
90 " THEN CAST('*' AS pg_catalog.text)\n"
91 " ELSE pg_catalog.pg_get_function_arguments(p.oid)\n"
100 " pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"\n"
101 "FROM pg_catalog.pg_proc p\n"
102 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n"
103 "WHERE p.prokind = " CppAsString2(PROKIND_AGGREGATE)
"\n",
107 " pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"\n"
108 "FROM pg_catalog.pg_proc p\n"
109 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n"
110 "WHERE p.proisagg\n",
113 if (!showSystem && !pattern)
115 " AND n.nspname <> 'information_schema'\n");
118 "n.nspname",
"p.proname", NULL,
119 "pg_catalog.pg_function_is_visible(p.oid)",
133 myopt.
title =
_(
"List of aggregate functions");
152 static const bool translate_columns[] = {
false,
true,
false,
false};
158 pg_log_error(
"The server (version %s) does not support access methods.",
160 sverbuf,
sizeof(sverbuf)));
167 "SELECT amname AS \"%s\",\n"
180 ",\n amhandler AS \"%s\",\n"
181 " pg_catalog.obj_description(oid, 'pg_am') AS \"%s\"",
187 "\nFROM pg_catalog.pg_am\n");
190 NULL,
"amname", NULL,
205 myopt.
title =
_(
"List of access methods");
230 "SELECT spcname AS \"%s\",\n"
231 " pg_catalog.pg_get_userbyid(spcowner) AS \"%s\",\n"
232 " pg_catalog.pg_tablespace_location(oid) AS \"%s\"",
242 ",\n spcoptions AS \"%s\""
243 ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_tablespace_size(oid)) AS \"%s\""
244 ",\n pg_catalog.shobj_description(oid, 'pg_tablespace') AS \"%s\"",
251 "\nFROM pg_catalog.pg_tablespace\n");
254 NULL,
"spcname", NULL,
269 myopt.
title =
_(
"List of tablespaces");
295 char **arg_patterns,
int num_arg_patterns,
298 bool showAggregate = strchr(functypes,
'a') != NULL;
299 bool showNormal = strchr(functypes,
'n') != NULL;
300 bool showProcedure = strchr(functypes,
'p') != NULL;
301 bool showTrigger = strchr(functypes,
't') != NULL;
302 bool showWindow = strchr(functypes,
'w') != NULL;
307 static const bool translate_columns[] = {
false,
false,
false,
false,
true,
true,
true,
false,
true,
false,
false,
false,
false};
310 static const bool translate_columns_pre_96[] = {
false,
false,
false,
false,
true,
true,
false,
true,
false,
false,
false,
false};
312 if (strlen(functypes) != strspn(functypes,
"anptwS+"))
322 pg_log_error(
"\\df does not take a \"%c\" option with server version %s",
325 sverbuf,
sizeof(sverbuf)));
329 if (!showAggregate && !showNormal && !showProcedure && !showTrigger && !showWindow)
331 showAggregate = showNormal = showTrigger = showWindow =
true;
333 showProcedure =
true;
339 "SELECT n.nspname as \"%s\",\n"
340 " p.proname as \"%s\",\n",
346 " pg_catalog.pg_get_function_result(p.oid) as \"%s\",\n"
347 " pg_catalog.pg_get_function_arguments(p.oid) as \"%s\",\n"
364 " pg_catalog.pg_get_function_result(p.oid) as \"%s\",\n"
365 " pg_catalog.pg_get_function_arguments(p.oid) as \"%s\",\n"
367 " WHEN p.proisagg THEN '%s'\n"
368 " WHEN p.proiswindow THEN '%s'\n"
369 " WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN '%s'\n"
385 " WHEN p.provolatile = "
387 " WHEN p.provolatile = "
389 " WHEN p.provolatile = "
399 " WHEN p.proparallel = "
401 " WHEN p.proparallel = "
403 " WHEN p.proparallel = "
411 ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\""
412 ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"",
420 ",\n l.lanname as \"%s\"",
423 ",\n CASE WHEN l.lanname IN ('internal', 'c') THEN p.prosrc END as \"%s\"",
426 ",\n pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"",
431 "\nFROM pg_catalog.pg_proc p"
432 "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n");
434 for (
int i = 0;
i < num_arg_patterns;
i++)
437 " LEFT JOIN pg_catalog.pg_type t%d ON t%d.oid = p.proargtypes[%d]\n"
438 " LEFT JOIN pg_catalog.pg_namespace nt%d ON nt%d.oid = t%d.typnamespace\n",
444 " LEFT JOIN pg_catalog.pg_language l ON l.oid = p.prolang\n");
449 if (showNormal && showAggregate && showProcedure && showTrigger && showWindow)
509 bool needs_or =
false;
528 "p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype\n");
553 "n.nspname",
"p.proname", NULL,
554 "pg_catalog.pg_function_is_visible(p.oid)",
558 for (
int i = 0;
i < num_arg_patterns;
i++)
560 if (strcmp(arg_patterns[
i],
"-") != 0)
572 snprintf(nspname,
sizeof(nspname),
"nt%d.nspname",
i);
575 "pg_catalog.format_type(t%d.oid, NULL)",
i);
577 "pg_catalog.pg_type_is_visible(t%d.oid)",
i);
592 if (!showSystem && !func_pattern)
594 " AND n.nspname <> 'information_schema'\n");
603 myopt.
title =
_(
"List of functions");
642 "SELECT n.nspname as \"%s\",\n"
643 " pg_catalog.format_type(t.oid, NULL) AS \"%s\",\n",
649 " t.typname AS \"%s\",\n"
650 " CASE WHEN t.typrelid != 0\n"
651 " THEN CAST('tuple' AS pg_catalog.text)\n"
652 " WHEN t.typlen < 0\n"
653 " THEN CAST('var' AS pg_catalog.text)\n"
654 " ELSE CAST(t.typlen AS pg_catalog.text)\n"
656 " pg_catalog.array_to_string(\n"
658 " SELECT e.enumlabel\n"
659 " FROM pg_catalog.pg_enum e\n"
660 " WHERE e.enumtypid = t.oid\n"
661 " ORDER BY e.enumsortorder\n"
665 " pg_catalog.pg_get_userbyid(t.typowner) AS \"%s\",\n",
675 " pg_catalog.obj_description(t.oid, 'pg_type') as \"%s\"\n",
679 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
687 " FROM pg_catalog.pg_class c "
688 "WHERE c.oid = t.typrelid))\n");
693 if (pattern == NULL || strstr(pattern,
"[]") == NULL)
694 appendPQExpBufferStr(&
buf,
" AND NOT EXISTS(SELECT 1 FROM pg_catalog.pg_type el WHERE el.oid = t.typelem AND el.typarray = t.oid)\n");
696 if (!showSystem && !pattern)
698 " AND n.nspname <> 'information_schema'\n");
703 "n.nspname",
"t.typname",
704 "pg_catalog.format_type(t.oid, NULL)",
705 "pg_catalog.pg_type_is_visible(t.oid)",
719 myopt.
title =
_(
"List of data types");
740 static const char *
const typename_map[] = {
746 "decimal",
"numeric",
747 "float",
"double precision",
754 "bool[]",
"boolean[]",
755 "decimal[]",
"numeric[]",
756 "float[]",
"double precision[]",
757 "float4[]",
"real[]",
758 "float8[]",
"double precision[]",
759 "int[]",
"integer[]",
760 "int2[]",
"smallint[]",
761 "int4[]",
"integer[]",
762 "int8[]",
"bigint[]",
763 "time[]",
"time without time zone[]",
764 "timetz[]",
"time with time zone[]",
765 "timestamp[]",
"timestamp without time zone[]",
766 "timestamptz[]",
"timestamp with time zone[]",
767 "varbit[]",
"bit varying[]",
768 "varchar[]",
"character varying[]",
774 for (
int i = 0; typename_map[
i] != NULL;
i += 2)
777 return typename_map[
i + 1];
789 char **arg_patterns,
int num_arg_patterns,
815 "SELECT n.nspname as \"%s\",\n"
816 " o.oprname AS \"%s\",\n"
817 " CASE WHEN o.oprkind='l' THEN NULL ELSE pg_catalog.format_type(o.oprleft, NULL) END AS \"%s\",\n"
818 " CASE WHEN o.oprkind='r' THEN NULL ELSE pg_catalog.format_type(o.oprright, NULL) END AS \"%s\",\n"
819 " pg_catalog.format_type(o.oprresult, NULL) AS \"%s\",\n",
828 " o.oprcode AS \"%s\",\n",
832 " coalesce(pg_catalog.obj_description(o.oid, 'pg_operator'),\n"
833 " pg_catalog.obj_description(o.oprcode, 'pg_proc')) AS \"%s\"\n"
834 "FROM pg_catalog.pg_operator o\n"
835 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = o.oprnamespace\n",
838 if (num_arg_patterns >= 2)
840 num_arg_patterns = 2;
842 " LEFT JOIN pg_catalog.pg_type t0 ON t0.oid = o.oprleft\n"
843 " LEFT JOIN pg_catalog.pg_namespace nt0 ON nt0.oid = t0.typnamespace\n"
844 " LEFT JOIN pg_catalog.pg_type t1 ON t1.oid = o.oprright\n"
845 " LEFT JOIN pg_catalog.pg_namespace nt1 ON nt1.oid = t1.typnamespace\n");
847 else if (num_arg_patterns == 1)
850 " LEFT JOIN pg_catalog.pg_type t0 ON t0.oid = o.oprright\n"
851 " LEFT JOIN pg_catalog.pg_namespace nt0 ON nt0.oid = t0.typnamespace\n");
854 if (!showSystem && !oper_pattern)
856 " AND n.nspname <> 'information_schema'\n");
859 !showSystem && !oper_pattern,
true,
860 "n.nspname",
"o.oprname", NULL,
861 "pg_catalog.pg_operator_is_visible(o.oid)",
865 if (num_arg_patterns == 1)
868 for (
int i = 0;
i < num_arg_patterns;
i++)
870 if (strcmp(arg_patterns[
i],
"-") != 0)
882 snprintf(nspname,
sizeof(nspname),
"nt%d.nspname",
i);
885 "pg_catalog.format_type(t%d.oid, NULL)",
i);
887 "pg_catalog.pg_type_is_visible(t%d.oid)",
i);
909 myopt.
title =
_(
"List of operators");
939 " d.datname as \"%s\",\n"
940 " pg_catalog.pg_get_userbyid(d.datdba) as \"%s\",\n"
941 " pg_catalog.pg_encoding_to_char(d.encoding) as \"%s\",\n",
947 " CASE d.datlocprovider "
948 "WHEN " CppAsString2(COLLPROVIDER_BUILTIN)
" THEN 'builtin' "
955 " 'libc' AS \"%s\",\n",
958 " d.datcollate as \"%s\",\n"
959 " d.datctype as \"%s\",\n",
964 " d.datlocale as \"%s\",\n",
968 " d.daticulocale as \"%s\",\n",
972 " NULL as \"%s\",\n",
976 " d.daticurules as \"%s\",\n",
980 " NULL as \"%s\",\n",
986 ",\n CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT')\n"
987 " THEN pg_catalog.pg_size_pretty(pg_catalog.pg_database_size(d.datname))\n"
988 " ELSE 'No Access'\n"
990 ",\n t.spcname as \"%s\""
991 ",\n pg_catalog.shobj_description(d.oid, 'pg_database') as \"%s\"",
996 "\nFROM pg_catalog.pg_database d\n");
999 " JOIN pg_catalog.pg_tablespace t on d.dattablespace = t.oid\n");
1004 NULL,
"d.datname", NULL, NULL,
1018 myopt.
title =
_(
"List of databases");
1038 static const bool translate_columns[] = {
false,
false,
true,
false,
false,
false};
1046 "SELECT n.nspname as \"%s\",\n"
1047 " c.relname as \"%s\",\n"
1053 " WHEN " CppAsString2(RELKIND_FOREIGN_TABLE)
" THEN '%s'"
1054 " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE)
" THEN '%s'"
1075 ",\n pg_catalog.array_to_string(ARRAY(\n"
1076 " SELECT attname || E':\\n ' || pg_catalog.array_to_string(attacl, E'\\n ')\n"
1077 " FROM pg_catalog.pg_attribute a\n"
1078 " WHERE attrelid = c.oid AND NOT attisdropped AND attacl IS NOT NULL\n"
1079 " ), E'\\n') AS \"%s\"",
1084 ",\n pg_catalog.array_to_string(ARRAY(\n"
1086 " || CASE WHEN polcmd != '*' THEN\n"
1087 " E' (' || polcmd::pg_catalog.text || E'):'\n"
1090 " || CASE WHEN polqual IS NOT NULL THEN\n"
1091 " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n"
1094 " || CASE WHEN polwithcheck IS NOT NULL THEN\n"
1095 " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n"
1098 " || CASE WHEN polroles <> '{0}' THEN\n"
1099 " E'\\n to: ' || pg_catalog.array_to_string(\n"
1102 " FROM pg_catalog.pg_roles\n"
1103 " WHERE oid = ANY (polroles)\n"
1108 " FROM pg_catalog.pg_policy pol\n"
1109 " WHERE polrelid = c.oid), E'\\n')\n"
1115 ",\n pg_catalog.array_to_string(ARRAY(\n"
1117 " || CASE WHEN NOT polpermissive THEN\n"
1118 " E' (RESTRICTIVE)'\n"
1120 " || CASE WHEN polcmd != '*' THEN\n"
1121 " E' (' || polcmd::pg_catalog.text || E'):'\n"
1124 " || CASE WHEN polqual IS NOT NULL THEN\n"
1125 " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n"
1128 " || CASE WHEN polwithcheck IS NOT NULL THEN\n"
1129 " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n"
1132 " || CASE WHEN polroles <> '{0}' THEN\n"
1133 " E'\\n to: ' || pg_catalog.array_to_string(\n"
1136 " FROM pg_catalog.pg_roles\n"
1137 " WHERE oid = ANY (polroles)\n"
1142 " FROM pg_catalog.pg_policy pol\n"
1143 " WHERE polrelid = c.oid), E'\\n')\n"
1148 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
1149 "WHERE c.relkind IN ("
1157 if (!showSystem && !pattern)
1159 " AND n.nspname <> 'information_schema'\n");
1162 "n.nspname",
"c.relname", NULL,
1163 "pg_catalog.pg_table_is_visible(c.oid)",
1202 static const bool translate_columns[] = {
false,
false,
true,
false};
1207 "SELECT pg_catalog.pg_get_userbyid(d.defaclrole) AS \"%s\",\n"
1208 " n.nspname AS \"%s\",\n"
1209 " 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"
1221 DEFACLOBJ_NAMESPACE,
1228 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.defaclnamespace\n");
1233 "pg_catalog.pg_get_userbyid(d.defaclrole)",
1279 static const bool translate_columns[] = {
false,
false,
true,
false};
1284 "SELECT DISTINCT tt.nspname AS \"%s\", tt.name AS \"%s\", tt.object AS \"%s\", d.description AS \"%s\"\n"
1293 " SELECT pgc.oid as oid, pgc.tableoid AS tableoid,\n"
1294 " n.nspname as nspname,\n"
1295 " CAST(pgc.conname AS pg_catalog.text) as name,"
1296 " CAST('%s' AS pg_catalog.text) as object\n"
1297 " FROM pg_catalog.pg_constraint pgc\n"
1298 " JOIN pg_catalog.pg_class c "
1299 "ON c.oid = pgc.conrelid\n"
1300 " LEFT JOIN pg_catalog.pg_namespace n "
1301 " ON n.oid = c.relnamespace\n",
1304 if (!showSystem && !pattern)
1306 " AND n.nspname <> 'information_schema'\n");
1309 false,
"n.nspname",
"pgc.conname", NULL,
1310 "pg_catalog.pg_table_is_visible(c.oid)",
1317 " SELECT pgc.oid as oid, pgc.tableoid AS tableoid,\n"
1318 " n.nspname as nspname,\n"
1319 " CAST(pgc.conname AS pg_catalog.text) as name,"
1320 " CAST('%s' AS pg_catalog.text) as object\n"
1321 " FROM pg_catalog.pg_constraint pgc\n"
1322 " JOIN pg_catalog.pg_type t "
1323 "ON t.oid = pgc.contypid\n"
1324 " LEFT JOIN pg_catalog.pg_namespace n "
1325 " ON n.oid = t.typnamespace\n",
1328 if (!showSystem && !pattern)
1330 " AND n.nspname <> 'information_schema'\n");
1333 false,
"n.nspname",
"pgc.conname", NULL,
1334 "pg_catalog.pg_type_is_visible(t.oid)",
1341 " SELECT o.oid as oid, o.tableoid as tableoid,\n"
1342 " n.nspname as nspname,\n"
1343 " CAST(o.opcname AS pg_catalog.text) as name,\n"
1344 " CAST('%s' AS pg_catalog.text) as object\n"
1345 " FROM pg_catalog.pg_opclass o\n"
1346 " JOIN pg_catalog.pg_am am ON "
1347 "o.opcmethod = am.oid\n"
1348 " JOIN pg_catalog.pg_namespace n ON "
1349 "n.oid = o.opcnamespace\n",
1352 if (!showSystem && !pattern)
1354 " AND n.nspname <> 'information_schema'\n");
1357 "n.nspname",
"o.opcname", NULL,
1358 "pg_catalog.pg_opclass_is_visible(o.oid)",
1365 " SELECT opf.oid as oid, opf.tableoid as tableoid,\n"
1366 " n.nspname as nspname,\n"
1367 " CAST(opf.opfname AS pg_catalog.text) AS name,\n"
1368 " CAST('%s' AS pg_catalog.text) as object\n"
1369 " FROM pg_catalog.pg_opfamily opf\n"
1370 " JOIN pg_catalog.pg_am am "
1371 "ON opf.opfmethod = am.oid\n"
1372 " JOIN pg_catalog.pg_namespace n "
1373 "ON opf.opfnamespace = n.oid\n",
1376 if (!showSystem && !pattern)
1378 " AND n.nspname <> 'information_schema'\n");
1381 "n.nspname",
"opf.opfname", NULL,
1382 "pg_catalog.pg_opfamily_is_visible(opf.oid)",
1389 " SELECT r.oid as oid, r.tableoid as tableoid,\n"
1390 " n.nspname as nspname,\n"
1391 " CAST(r.rulename AS pg_catalog.text) as name,"
1392 " CAST('%s' AS pg_catalog.text) as object\n"
1393 " FROM pg_catalog.pg_rewrite r\n"
1394 " JOIN pg_catalog.pg_class c ON c.oid = r.ev_class\n"
1395 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
1396 " WHERE r.rulename != '_RETURN'\n",
1399 if (!showSystem && !pattern)
1401 " AND n.nspname <> 'information_schema'\n");
1404 "n.nspname",
"r.rulename", NULL,
1405 "pg_catalog.pg_table_is_visible(c.oid)",
1412 " SELECT t.oid as oid, t.tableoid as tableoid,\n"
1413 " n.nspname as nspname,\n"
1414 " CAST(t.tgname AS pg_catalog.text) as name,"
1415 " CAST('%s' AS pg_catalog.text) as object\n"
1416 " FROM pg_catalog.pg_trigger t\n"
1417 " JOIN pg_catalog.pg_class c ON c.oid = t.tgrelid\n"
1418 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n",
1421 if (!showSystem && !pattern)
1423 " AND n.nspname <> 'information_schema'\n");
1426 "n.nspname",
"t.tgname", NULL,
1427 "pg_catalog.pg_table_is_visible(c.oid)",
1433 " JOIN pg_catalog.pg_description d ON (tt.oid = d.objoid AND tt.tableoid = d.classoid AND d.objsubid = 0)\n");
1442 myopt.
title =
_(
"Object descriptions");
1479 "FROM pg_catalog.pg_class c\n"
1480 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n");
1482 if (!showSystem && !pattern)
1484 " AND n.nspname <> 'information_schema'\n");
1487 "n.nspname",
"c.relname", NULL,
1488 "pg_catalog.pg_table_is_visible(c.oid)",
1507 pg_log_error(
"Did not find any relation named \"%s\".",
1519 const char *nspname;
1551 const char *relationname,
1555 bool retval =
false;
1560 bool printTableInitialized =
false;
1562 char *view_def = NULL;
1567 int attname_col = -1,
1570 attnotnull_col = -1,
1572 attidentity_col = -1,
1573 attgenerated_col = -1,
1574 isindexkey_col = -1,
1577 attstorage_col = -1,
1578 attcompression_col = -1,
1579 attstattarget_col = -1,
1590 bool forcerowsecurity;
1596 char relpersistence;
1600 bool show_column_details =
false;
1614 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1615 "c.relhastriggers, c.relrowsecurity, c.relforcerowsecurity, "
1616 "false AS relhasoids, c.relispartition, %s, c.reltablespace, "
1617 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
1618 "c.relpersistence, c.relreplident, am.amname\n"
1619 "FROM pg_catalog.pg_class c\n "
1620 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1621 "LEFT JOIN pg_catalog.pg_am am ON (c.relam = am.oid)\n"
1622 "WHERE c.oid = '%s';",
1624 "pg_catalog.array_to_string(c.reloptions || "
1625 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1632 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1633 "c.relhastriggers, c.relrowsecurity, c.relforcerowsecurity, "
1634 "c.relhasoids, c.relispartition, %s, c.reltablespace, "
1635 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
1636 "c.relpersistence, c.relreplident\n"
1637 "FROM pg_catalog.pg_class c\n "
1638 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1639 "WHERE c.oid = '%s';",
1641 "pg_catalog.array_to_string(c.reloptions || "
1642 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1649 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1650 "c.relhastriggers, c.relrowsecurity, c.relforcerowsecurity, "
1651 "c.relhasoids, false as relispartition, %s, c.reltablespace, "
1652 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
1653 "c.relpersistence, c.relreplident\n"
1654 "FROM pg_catalog.pg_class c\n "
1655 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1656 "WHERE c.oid = '%s';",
1658 "pg_catalog.array_to_string(c.reloptions || "
1659 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1666 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1667 "c.relhastriggers, false, false, c.relhasoids, "
1668 "false as relispartition, %s, c.reltablespace, "
1669 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
1670 "c.relpersistence, c.relreplident\n"
1671 "FROM pg_catalog.pg_class c\n "
1672 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1673 "WHERE c.oid = '%s';",
1675 "pg_catalog.array_to_string(c.reloptions || "
1676 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1683 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1684 "c.relhastriggers, false, false, c.relhasoids, "
1685 "false as relispartition, %s, c.reltablespace, "
1686 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
1687 "c.relpersistence\n"
1688 "FROM pg_catalog.pg_class c\n "
1689 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1690 "WHERE c.oid = '%s';",
1692 "pg_catalog.array_to_string(c.reloptions || "
1693 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1706 pg_log_error(
"Did not find any relation with OID %s.", oid);
1712 tableinfo.hasindex = strcmp(
PQgetvalue(
res, 0, 2),
"t") == 0;
1713 tableinfo.hasrules = strcmp(
PQgetvalue(
res, 0, 3),
"t") == 0;
1714 tableinfo.hastriggers = strcmp(
PQgetvalue(
res, 0, 4),
"t") == 0;
1715 tableinfo.rowsecurity = strcmp(
PQgetvalue(
res, 0, 5),
"t") == 0;
1716 tableinfo.forcerowsecurity = strcmp(
PQgetvalue(
res, 0, 6),
"t") == 0;
1717 tableinfo.hasoids = strcmp(
PQgetvalue(
res, 0, 7),
"t") == 0;
1718 tableinfo.ispartition = strcmp(
PQgetvalue(
res, 0, 8),
"t") == 0;
1721 tableinfo.reloftype = (strcmp(
PQgetvalue(
res, 0, 11),
"") != 0) ?
1730 tableinfo.relam = NULL;
1737 if (tableinfo.relkind == RELKIND_SEQUENCE)
1741 char *footers[2] = {NULL, NULL};
1746 "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n"
1747 " seqstart AS \"%s\",\n"
1748 " seqmin AS \"%s\",\n"
1749 " seqmax AS \"%s\",\n"
1750 " seqincrement AS \"%s\",\n"
1751 " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n"
1752 " seqcache AS \"%s\"\n",
1763 "FROM pg_catalog.pg_sequence\n"
1764 "WHERE seqrelid = '%s';",
1770 "SELECT 'bigint' AS \"%s\",\n"
1771 " start_value AS \"%s\",\n"
1772 " min_value AS \"%s\",\n"
1773 " max_value AS \"%s\",\n"
1774 " increment_by AS \"%s\",\n"
1775 " CASE WHEN is_cycled THEN '%s' ELSE '%s' END AS \"%s\",\n"
1776 " cache_value AS \"%s\"\n",
1797 "\n pg_catalog.quote_ident(relname) || '.' ||"
1798 "\n pg_catalog.quote_ident(attname),"
1800 "\nFROM pg_catalog.pg_class c"
1801 "\nINNER JOIN pg_catalog.pg_depend d ON c.oid=d.refobjid"
1802 "\nINNER JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace"
1803 "\nINNER JOIN pg_catalog.pg_attribute a ON ("
1804 "\n a.attrelid=c.oid AND"
1805 "\n a.attnum=d.refobjsubid)"
1806 "\nWHERE d.classid='pg_catalog.pg_class'::pg_catalog.regclass"
1807 "\n AND d.refclassid='pg_catalog.pg_class'::pg_catalog.regclass"
1808 "\n AND d.objid='%s'"
1809 "\n AND d.deptype IN ('a', 'i')",
1826 footers[0] =
psprintf(
_(
"Owned by: %s"),
1830 footers[0] =
psprintf(
_(
"Sequence for identity column: %s"),
1837 if (tableinfo.relpersistence == RELPERSISTENCE_UNLOGGED)
1839 schemaname, relationname);
1842 schemaname, relationname);
1858 if (tableinfo.relkind == RELKIND_RELATION ||
1859 tableinfo.relkind == RELKIND_VIEW ||
1860 tableinfo.relkind == RELKIND_MATVIEW ||
1861 tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
1862 tableinfo.relkind == RELKIND_COMPOSITE_TYPE ||
1863 tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
1864 show_column_details =
true;
1876 attname_col = cols++;
1878 atttype_col = cols++;
1880 if (show_column_details)
1884 ",\n (SELECT pg_catalog.pg_get_expr(d.adbin, d.adrelid, true)"
1885 "\n FROM pg_catalog.pg_attrdef d"
1886 "\n WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef)"
1887 ",\n a.attnotnull");
1888 attrdef_col = cols++;
1889 attnotnull_col = cols++;
1891 " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation");
1892 attcoll_col = cols++;
1897 attidentity_col = cols++;
1902 attgenerated_col = cols++;
1904 if (tableinfo.relkind == RELKIND_INDEX ||
1905 tableinfo.relkind == RELKIND_PARTITIONED_INDEX)
1909 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",
1913 isindexkey_col = cols++;
1916 indexdef_col = cols++;
1919 if (tableinfo.relkind == RELKIND_FOREIGN_TABLE)
1922 " '(' || pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(option_name) || ' ' || pg_catalog.quote_literal(option_value) FROM "
1923 " pg_catalog.pg_options_to_table(attfdwoptions)), ', ') || ')' END AS attfdwoptions");
1924 fdwopts_col = cols++;
1929 attstorage_col = cols++;
1934 (tableinfo.relkind == RELKIND_RELATION ||
1935 tableinfo.relkind == RELKIND_PARTITIONED_TABLE ||
1936 tableinfo.relkind == RELKIND_MATVIEW))
1939 attcompression_col = cols++;
1943 if (tableinfo.relkind == RELKIND_RELATION ||
1944 tableinfo.relkind == RELKIND_INDEX ||
1945 tableinfo.relkind == RELKIND_PARTITIONED_INDEX ||
1946 tableinfo.relkind == RELKIND_MATVIEW ||
1947 tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
1948 tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
1950 appendPQExpBufferStr(&
buf,
",\n CASE WHEN a.attstattarget=-1 THEN NULL ELSE a.attstattarget END AS attstattarget");
1951 attstattarget_col = cols++;
1958 if (tableinfo.relkind == RELKIND_RELATION ||
1959 tableinfo.relkind == RELKIND_VIEW ||
1960 tableinfo.relkind == RELKIND_MATVIEW ||
1961 tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
1962 tableinfo.relkind == RELKIND_COMPOSITE_TYPE ||
1963 tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
1966 attdescr_col = cols++;
1971 appendPQExpBuffer(&
buf,
"\nWHERE a.attrelid = '%s' AND a.attnum > 0 AND NOT a.attisdropped", oid);
1980 switch (tableinfo.relkind)
1982 case RELKIND_RELATION:
1983 if (tableinfo.relpersistence == RELPERSISTENCE_UNLOGGED)
1985 schemaname, relationname);
1988 schemaname, relationname);
1992 schemaname, relationname);
1994 case RELKIND_MATVIEW:
1996 schemaname, relationname);
1999 if (tableinfo.relpersistence == RELPERSISTENCE_UNLOGGED)
2001 schemaname, relationname);
2004 schemaname, relationname);
2006 case RELKIND_PARTITIONED_INDEX:
2007 if (tableinfo.relpersistence == RELPERSISTENCE_UNLOGGED)
2009 schemaname, relationname);
2012 schemaname, relationname);
2014 case RELKIND_TOASTVALUE:
2016 schemaname, relationname);
2018 case RELKIND_COMPOSITE_TYPE:
2020 schemaname, relationname);
2022 case RELKIND_FOREIGN_TABLE:
2024 schemaname, relationname);
2026 case RELKIND_PARTITIONED_TABLE:
2027 if (tableinfo.relpersistence == RELPERSISTENCE_UNLOGGED)
2029 schemaname, relationname);
2032 schemaname, relationname);
2037 tableinfo.relkind, schemaname, relationname);
2045 if (show_column_details)
2051 if (isindexkey_col >= 0)
2053 if (indexdef_col >= 0)
2055 if (fdwopts_col >= 0)
2057 if (attstorage_col >= 0)
2059 if (attcompression_col >= 0)
2061 if (attstattarget_col >= 0)
2063 if (attdescr_col >= 0)
2069 printTableInitialized =
true;
2071 for (
i = 0;
i < cols;
i++)
2075 for (
i = 0;
i < numrows;
i++)
2084 if (show_column_details)
2089 bool mustfree =
false;
2094 strcmp(
PQgetvalue(
res,
i, attnotnull_col),
"t") == 0 ?
"not null" :
"",
2100 if (identity[0] == ATTRIBUTE_IDENTITY_ALWAYS)
2101 default_str =
"generated always as identity";
2102 else if (identity[0] == ATTRIBUTE_IDENTITY_BY_DEFAULT)
2103 default_str =
"generated by default as identity";
2104 else if (generated[0] == ATTRIBUTE_GENERATED_STORED)
2106 default_str =
psprintf(
"generated always as (%s) stored",
2117 if (isindexkey_col >= 0)
2119 if (indexdef_col >= 0)
2123 if (fdwopts_col >= 0)
2127 if (attstorage_col >= 0)
2133 (
storage[0] == TYPSTORAGE_MAIN ?
"main" :
2134 (
storage[0] == TYPSTORAGE_EXTENDED ?
"extended" :
2135 (
storage[0] == TYPSTORAGE_EXTERNAL ?
"external" :
2141 if (attcompression_col >= 0)
2147 (compression[0] ==
'l' ?
"lz4" :
2148 (compression[0] ==
'\0' ?
"" :
2154 if (attstattarget_col >= 0)
2159 if (attdescr_col >= 0)
2166 if (tableinfo.ispartition)
2172 "SELECT inhparent::pg_catalog.regclass,\n"
2173 " pg_catalog.pg_get_expr(c.relpartbound, c.oid),\n ");
2177 "false as inhdetachpending");
2182 ",\n pg_catalog.pg_get_partition_constraintdef(c.oid)");
2184 "\nFROM pg_catalog.pg_class c"
2185 " JOIN pg_catalog.pg_inherits i"
2186 " ON c.oid = inhrelid"
2187 "\nWHERE c.oid = '%s';", oid);
2194 char *parent_name =
PQgetvalue(result, 0, 0);
2200 strcmp(detached,
"t") == 0 ?
" DETACH PENDING" :
"");
2205 char *partconstraintdef = NULL;
2208 partconstraintdef =
PQgetvalue(result, 0, 3);
2210 if (partconstraintdef == NULL || partconstraintdef[0] ==
'\0')
2221 if (tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
2227 "SELECT pg_catalog.pg_get_partkeydef('%s'::pg_catalog.oid);",
2243 if (tableinfo.relkind == RELKIND_TOASTVALUE)
2249 "SELECT n.nspname, c.relname\n"
2250 "FROM pg_catalog.pg_class c"
2251 " JOIN pg_catalog.pg_namespace n"
2252 " ON n.oid = c.relnamespace\n"
2253 "WHERE reltoastrelid = '%s';", oid);
2270 if (tableinfo.relkind == RELKIND_INDEX ||
2271 tableinfo.relkind == RELKIND_PARTITIONED_INDEX)
2277 "SELECT i.indisunique, i.indisprimary, i.indisclustered, "
2279 " (NOT i.indimmediate) AND "
2280 "EXISTS (SELECT 1 FROM pg_catalog.pg_constraint "
2281 "WHERE conrelid = i.indrelid AND "
2282 "conindid = i.indexrelid AND "
2286 "condeferrable) AS condeferrable,\n"
2287 " (NOT i.indimmediate) AND "
2288 "EXISTS (SELECT 1 FROM pg_catalog.pg_constraint "
2289 "WHERE conrelid = i.indrelid AND "
2290 "conindid = i.indexrelid AND "
2294 "condeferred) AS condeferred,\n");
2307 "pg_catalog.pg_get_expr(i.indpred, i.indrelid, true)\n"
2308 "FROM pg_catalog.pg_index i, pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_am a\n"
2309 "WHERE i.indexrelid = c.oid AND c.oid = '%s' AND c.relam = a.oid\n"
2310 "AND i.indrelid = c2.oid;",
2323 char *indisunique =
PQgetvalue(result, 0, 0);
2324 char *indisprimary =
PQgetvalue(result, 0, 1);
2325 char *indisclustered =
PQgetvalue(result, 0, 2);
2329 char *indisreplident =
PQgetvalue(result, 0, 6);
2330 char *indnullsnotdistinct =
PQgetvalue(result, 0, 7);
2335 if (strcmp(indisprimary,
"t") == 0)
2337 else if (strcmp(indisunique,
"t") == 0)
2340 if (strcmp(indnullsnotdistinct,
"t") == 0)
2350 schemaname, indtable);
2352 if (strlen(indpred))
2355 if (strcmp(indisclustered,
"t") == 0)
2358 if (strcmp(indisvalid,
"t") != 0)
2361 if (strcmp(deferrable,
"t") == 0)
2364 if (strcmp(deferred,
"t") == 0)
2367 if (strcmp(indisreplident,
"t") == 0)
2375 if (tableinfo.relkind == RELKIND_INDEX)
2377 tableinfo.tablespace,
true);
2383 else if (tableinfo.relkind == RELKIND_RELATION ||
2384 tableinfo.relkind == RELKIND_MATVIEW ||
2385 tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
2386 tableinfo.relkind == RELKIND_PARTITIONED_TABLE ||
2387 tableinfo.relkind == RELKIND_PARTITIONED_INDEX ||
2388 tableinfo.relkind == RELKIND_TOASTVALUE)
2395 if (tableinfo.hasindex)
2398 "SELECT c2.relname, i.indisprimary, i.indisunique, "
2399 "i.indisclustered, i.indisvalid, "
2400 "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n "
2401 "pg_catalog.pg_get_constraintdef(con.oid, true), "
2402 "contype, condeferrable, condeferred");
2413 "\nFROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i\n"
2414 " LEFT JOIN pg_catalog.pg_constraint con ON (conrelid = i.indrelid AND conindid = i.indexrelid AND contype IN ("
2418 "WHERE c.oid = '%s' AND c.oid = i.indrelid AND i.indexrelid = c2.oid\n"
2419 "ORDER BY i.indisprimary DESC, c2.relname;",
2430 for (
i = 0;
i < tuples;
i++)
2448 const char *indexdef;
2449 const char *usingpos;
2454 else if (strcmp(
PQgetvalue(result,
i, 2),
"t") == 0)
2464 usingpos = strstr(indexdef,
" USING ");
2466 indexdef = usingpos + 7;
2499 if (tableinfo.checks)
2502 "SELECT r.conname, "
2503 "pg_catalog.pg_get_constraintdef(r.oid, true)\n"
2504 "FROM pg_catalog.pg_constraint r\n"
2505 "WHERE r.conrelid = '%s' "
2518 for (
i = 0;
i < tuples;
i++)
2536 if (tableinfo.hastriggers ||
2537 tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
2540 (tableinfo.ispartition || tableinfo.relkind == RELKIND_PARTITIONED_TABLE))
2547 "SELECT conrelid = '%s'::pg_catalog.regclass AS sametable,\n"
2549 " pg_catalog.pg_get_constraintdef(oid, true) AS condef,\n"
2550 " conrelid::pg_catalog.regclass AS ontable\n"
2551 " FROM pg_catalog.pg_constraint,\n"
2552 " pg_catalog.pg_partition_ancestors('%s')\n"
2553 " WHERE conrelid = relid AND contype = " CppAsString2(CONSTRAINT_FOREIGN)
" AND conparentid = 0\n"
2554 "ORDER BY sametable DESC, conname;",
2560 "SELECT true as sametable, conname,\n"
2561 " pg_catalog.pg_get_constraintdef(r.oid, true) as condef,\n"
2562 " conrelid::pg_catalog.regclass AS ontable\n"
2563 "FROM pg_catalog.pg_constraint r\n"
2564 "WHERE r.conrelid = '%s' AND r.contype = " CppAsString2(CONSTRAINT_FOREIGN)
"\n",
2580 int i_sametable =
PQfnumber(result,
"sametable"),
2581 i_conname =
PQfnumber(result,
"conname"),
2583 i_ontable =
PQfnumber(result,
"ontable");
2586 for (
i = 0;
i < tuples;
i++)
2593 if (strcmp(
PQgetvalue(result,
i, i_sametable),
"f") == 0)
2610 if (tableinfo.hastriggers ||
2611 tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
2616 "SELECT conname, conrelid::pg_catalog.regclass AS ontable,\n"
2617 " pg_catalog.pg_get_constraintdef(oid, true) AS condef\n"
2618 " FROM pg_catalog.pg_constraint c\n"
2619 " WHERE confrelid IN (SELECT pg_catalog.pg_partition_ancestors('%s')\n"
2620 " UNION ALL VALUES ('%s'::pg_catalog.regclass))\n"
2621 " AND contype = " CppAsString2(CONSTRAINT_FOREIGN)
" AND conparentid = 0\n"
2622 "ORDER BY conname;",
2628 "SELECT conname, conrelid::pg_catalog.regclass AS ontable,\n"
2629 " pg_catalog.pg_get_constraintdef(oid, true) AS condef\n"
2630 " FROM pg_catalog.pg_constraint\n"
2631 " WHERE confrelid = %s AND contype = " CppAsString2(CONSTRAINT_FOREIGN)
"\n"
2632 "ORDER BY conname;",
2644 int i_conname =
PQfnumber(result,
"conname"),
2645 i_ontable =
PQfnumber(result,
"ontable"),
2649 for (
i = 0;
i < tuples;
i++)
2668 " pol.polpermissive,\n");
2671 " 't' as polpermissive,\n");
2673 " 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"
2674 " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n"
2675 " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n"
2676 " CASE pol.polcmd\n"
2677 " WHEN 'r' THEN 'SELECT'\n"
2678 " WHEN 'a' THEN 'INSERT'\n"
2679 " WHEN 'w' THEN 'UPDATE'\n"
2680 " WHEN 'd' THEN 'DELETE'\n"
2682 "FROM pg_catalog.pg_policy pol\n"
2683 "WHERE pol.polrelid = '%s' ORDER BY 1;",
2697 if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0)
2700 if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0)
2703 if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0)
2706 if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0)
2709 if (!tableinfo.rowsecurity && tuples > 0)
2713 for (
i = 0;
i < tuples;
i++)
2749 "stxrelid::pg_catalog.regclass, "
2750 "stxnamespace::pg_catalog.regnamespace::pg_catalog.text AS nsp, "
2752 "pg_catalog.pg_get_statisticsobjdef_columns(oid) AS columns,\n"
2753 " " CppAsString2(STATS_EXT_NDISTINCT)
" = any(stxkind) AS ndist_enabled,\n"
2754 " " CppAsString2(STATS_EXT_DEPENDENCIES)
" = any(stxkind) AS deps_enabled,\n"
2755 " " CppAsString2(STATS_EXT_MCV)
" = any(stxkind) AS mcv_enabled,\n"
2757 "FROM pg_catalog.pg_statistic_ext\n"
2758 "WHERE stxrelid = '%s'\n"
2759 "ORDER BY nsp, stxname;",
2772 for (
i = 0;
i < tuples;
i++)
2774 bool gotone =
false;
2776 bool has_dependencies;
2781 has_ndistinct = (strcmp(
PQgetvalue(result,
i, 5),
"t") == 0);
2782 has_dependencies = (strcmp(
PQgetvalue(result,
i, 6),
"t") == 0);
2783 has_mcv = (strcmp(
PQgetvalue(result,
i, 7),
"t") == 0);
2800 has_all = (has_ndistinct && has_dependencies && has_mcv);
2801 has_some = (has_ndistinct || has_dependencies || has_mcv);
2803 if (has_some && !has_all)
2814 if (has_dependencies)
2847 "stxrelid::pg_catalog.regclass, "
2848 "stxnamespace::pg_catalog.regnamespace AS nsp, "
2850 " (SELECT pg_catalog.string_agg(pg_catalog.quote_ident(attname),', ')\n"
2851 " FROM pg_catalog.unnest(stxkeys) s(attnum)\n"
2852 " JOIN pg_catalog.pg_attribute a ON (stxrelid = a.attrelid AND\n"
2853 " a.attnum = s.attnum AND NOT attisdropped)) AS columns,\n"
2854 " " CppAsString2(STATS_EXT_NDISTINCT)
" = any(stxkind) AS ndist_enabled,\n"
2855 " " CppAsString2(STATS_EXT_DEPENDENCIES)
" = any(stxkind) AS deps_enabled,\n"
2856 " " CppAsString2(STATS_EXT_MCV)
" = any(stxkind) AS mcv_enabled,\n");
2863 "WHERE stxrelid = '%s'\n"
2877 for (
i = 0;
i < tuples;
i++)
2879 bool gotone =
false;
2922 if (tableinfo.hasrules && tableinfo.relkind != RELKIND_MATVIEW)
2925 "SELECT r.rulename, trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true)), "
2927 "FROM pg_catalog.pg_rewrite r\n"
2928 "WHERE r.ev_class = '%s' ORDER BY 1;",
2941 for (category = 0; category < 4; category++)
2943 have_heading =
false;
2945 for (
i = 0;
i < tuples;
i++)
2947 const char *ruledef;
2948 bool list_rule =
false;
2990 have_heading =
true;
3013 "FROM pg_catalog.pg_publication p\n"
3014 " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n"
3015 " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n"
3016 "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n"
3019 " , pg_get_expr(pr.prqual, c.oid)\n"
3020 " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n"
3021 " (SELECT string_agg(attname, ', ')\n"
3022 " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n"
3023 " pg_catalog.pg_attribute\n"
3024 " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n"
3026 "FROM pg_catalog.pg_publication p\n"
3027 " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n"
3028 " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n"
3029 "WHERE pr.prrelid = '%s'\n"
3034 "FROM pg_catalog.pg_publication p\n"
3035 "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n"
3037 oid, oid, oid, oid);
3045 "FROM pg_catalog.pg_publication p\n"
3046 "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n"
3047 "WHERE pr.prrelid = '%s'\n"
3052 "FROM pg_catalog.pg_publication p\n"
3053 "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n"
3068 for (
i = 0;
i < tuples;
i++)
3094 "SELECT c.conname, a.attname, c.connoinherit,\n"
3095 " c.conislocal, c.coninhcount <> 0\n"
3096 "FROM pg_catalog.pg_constraint c JOIN\n"
3097 " pg_catalog.pg_attribute a ON\n"
3098 " (a.attrelid = c.conrelid AND a.attnum = c.conkey[1])\n"
3099 "WHERE c.contype = " CppAsString2(CONSTRAINT_NOTNULL)
" AND\n"
3100 " c.conrelid = '%s'::pg_catalog.regclass\n"
3101 "ORDER BY a.attnum",
3114 for (
i = 0;
i < tuples;
i++)
3116 bool islocal =
PQgetvalue(result,
i, 3)[0] ==
't';
3117 bool inherited =
PQgetvalue(result,
i, 4)[0] ==
't';
3124 islocal && inherited ?
_(
" (local, inherited)") :
3125 inherited ?
_(
" (inherited)") :
"");
3134 if ((tableinfo.relkind == RELKIND_VIEW ||
3135 tableinfo.relkind == RELKIND_MATVIEW) &&
verbose)
3140 "SELECT pg_catalog.pg_get_viewdef('%s'::pg_catalog.oid, true);",
3161 if (tableinfo.hasrules)
3164 "SELECT r.rulename, trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true))\n"
3165 "FROM pg_catalog.pg_rewrite r\n"
3166 "WHERE r.ev_class = '%s' AND r.rulename != '_RETURN' ORDER BY 1;",
3177 const char *ruledef;
3195 if (tableinfo.hastriggers)
3202 "pg_catalog.pg_get_triggerdef(t.oid, true), "
3203 "t.tgenabled, t.tgisinternal,\n");
3221 " CASE WHEN t.tgparentid != 0 THEN\n"
3222 " (SELECT u.tgrelid::pg_catalog.regclass\n"
3223 " FROM pg_catalog.pg_trigger AS u,\n"
3224 " pg_catalog.pg_partition_ancestors(t.tgrelid) WITH ORDINALITY AS a(relid, depth)\n"
3225 " WHERE u.tgname = t.tgname AND u.tgrelid = a.relid\n"
3226 " AND u.tgparentid = 0\n"
3227 " ORDER BY a.depth LIMIT 1)\n"
3228 " END AS parent\n");
3233 "FROM pg_catalog.pg_trigger t\n"
3234 "WHERE t.tgrelid = '%s' AND ",
3246 " OR EXISTS (SELECT 1 FROM pg_catalog.pg_depend WHERE objid = t.oid \n"
3247 " AND refclassid = 'pg_catalog.pg_trigger'::pg_catalog.regclass))");
3269 for (category = 0; category <= 4; category++)
3271 have_heading =
false;
3272 for (
i = 0;
i < tuples;
i++)
3276 const char *usingpos;
3277 const char *tgenabled;
3278 const char *tgisinternal;
3285 list_trigger =
false;
3289 if (*tgenabled ==
'O' || *tgenabled ==
't')
3290 list_trigger =
true;
3293 if ((*tgenabled ==
'D' || *tgenabled ==
'f') &&
3294 *tgisinternal ==
'f')
3295 list_trigger =
true;
3298 if ((*tgenabled ==
'D' || *tgenabled ==
'f') &&
3299 *tgisinternal ==
't')
3300 list_trigger =
true;
3303 if (*tgenabled ==
'A')
3304 list_trigger =
true;
3307 if (*tgenabled ==
'R')
3308 list_trigger =
true;
3311 if (list_trigger ==
false)
3315 if (have_heading ==
false)
3336 have_heading =
true;
3341 usingpos = strstr(tgdef,
" TRIGGER ");
3343 tgdef = usingpos + 9;
3362 if (tableinfo.relkind == RELKIND_RELATION ||
3363 tableinfo.relkind == RELKIND_MATVIEW ||
3364 tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
3365 tableinfo.relkind == RELKIND_PARTITIONED_TABLE ||
3366 tableinfo.relkind == RELKIND_PARTITIONED_INDEX ||
3367 tableinfo.relkind == RELKIND_TOASTVALUE)
3369 bool is_partitioned;
3374 is_partitioned = (tableinfo.relkind == RELKIND_PARTITIONED_TABLE ||
3375 tableinfo.relkind == RELKIND_PARTITIONED_INDEX);
3378 if (tableinfo.relkind == RELKIND_FOREIGN_TABLE)
3384 "SELECT s.srvname,\n"
3385 " pg_catalog.array_to_string(ARRAY(\n"
3386 " SELECT pg_catalog.quote_ident(option_name)"
3387 " || ' ' || pg_catalog.quote_literal(option_value)\n"
3388 " FROM pg_catalog.pg_options_to_table(ftoptions)), ', ')\n"
3389 "FROM pg_catalog.pg_foreign_table f,\n"
3390 " pg_catalog.pg_foreign_server s\n"
3391 "WHERE f.ftrelid = '%s' AND s.oid = f.ftserver;",
3409 if (ftoptions && ftoptions[0] !=
'\0')
3419 "SELECT c.oid::pg_catalog.regclass\n"
3420 "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n"
3421 "WHERE c.oid = i.inhparent AND i.inhrelid = '%s'\n"
3422 " AND c.relkind != " CppAsString2(RELKIND_PARTITIONED_TABLE)
3423 " AND c.relkind != " CppAsString2(RELKIND_PARTITIONED_INDEX)
3424 "\nORDER BY inhseqno;",
3432 const char *s =
_(
"Inherits");
3437 for (
i = 0;
i < tuples;
i++)
3457 "SELECT c.oid::pg_catalog.regclass, c.relkind,"
3458 " inhdetachpending,"
3459 " pg_catalog.pg_get_expr(c.relpartbound, c.oid)\n"
3460 "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n"
3461 "WHERE c.oid = i.inhrelid AND i.inhparent = '%s'\n"
3462 "ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT',"
3463 " c.oid::pg_catalog.regclass::pg_catalog.text;",
3467 "SELECT c.oid::pg_catalog.regclass, c.relkind,"
3468 " false AS inhdetachpending,"
3469 " pg_catalog.pg_get_expr(c.relpartbound, c.oid)\n"
3470 "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n"
3471 "WHERE c.oid = i.inhrelid AND i.inhparent = '%s'\n"
3472 "ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT',"
3473 " c.oid::pg_catalog.regclass::pg_catalog.text;",
3477 "SELECT c.oid::pg_catalog.regclass, c.relkind,"
3478 " false AS inhdetachpending, NULL\n"
3479 "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n"
3480 "WHERE c.oid = i.inhrelid AND i.inhparent = '%s'\n"
3481 "ORDER BY c.oid::pg_catalog.regclass::pg_catalog.text;",
3495 if (is_partitioned && tuples == 0)
3515 const char *ct = is_partitioned ?
_(
"Partitions") :
_(
"Child tables");
3518 for (
i = 0;
i < tuples;
i++)
3530 if (child_relkind == RELKIND_PARTITIONED_TABLE ||
3531 child_relkind == RELKIND_PARTITIONED_INDEX)
3533 else if (child_relkind == RELKIND_FOREIGN_TABLE)
3546 if (tableinfo.reloftype)
3553 (tableinfo.relkind == RELKIND_RELATION ||
3554 tableinfo.relkind == RELKIND_MATVIEW) &&
3560 tableinfo.relreplident != REPLICA_IDENTITY_INDEX &&
3561 ((strcmp(schemaname,
"pg_catalog") != 0 &&
3562 tableinfo.relreplident != REPLICA_IDENTITY_DEFAULT) ||
3563 (strcmp(schemaname,
"pg_catalog") == 0 &&
3564 tableinfo.relreplident != REPLICA_IDENTITY_NOTHING)))
3566 const char *s =
_(
"Replica Identity");
3570 tableinfo.relreplident == REPLICA_IDENTITY_FULL ?
"FULL" :
3571 tableinfo.relreplident == REPLICA_IDENTITY_DEFAULT ?
"NOTHING" :
3578 if (
verbose && tableinfo.relkind != RELKIND_MATVIEW && tableinfo.hasoids)
3595 tableinfo.reloptions && tableinfo.reloptions[0] !=
'\0')
3597 const char *t =
_(
"Options");
3610 if (printTableInitialized)
3633 if (relkind == RELKIND_RELATION ||
3634 relkind == RELKIND_MATVIEW ||
3635 relkind == RELKIND_INDEX ||
3636 relkind == RELKIND_PARTITIONED_TABLE ||
3637 relkind == RELKIND_PARTITIONED_INDEX ||
3638 relkind == RELKIND_TOASTVALUE)
3651 "SELECT spcname FROM pg_catalog.pg_tablespace\n"
3704 const char align =
'l';
3712 "SELECT r.rolname, r.rolsuper, r.rolinherit,\n"
3713 " r.rolcreaterole, r.rolcreatedb, r.rolcanlogin,\n"
3714 " r.rolconnlimit, r.rolvaliduntil");
3730 if (!showSystem && !pattern)
3734 NULL,
"r.rolname", NULL, NULL,
3748 attr =
pg_malloc0((nrows + 1) *
sizeof(*attr));
3758 for (
i = 0;
i < nrows;
i++)
3820 for (
i = 0;
i < nrows;
i++)
3851 "pg_catalog.array_to_string(setconfig, E'\\n') AS \"%s\"\n"
3852 "FROM pg_catalog.pg_db_role_setting s\n"
3853 "LEFT JOIN pg_catalog.pg_database d ON d.oid = setdatabase\n"
3854 "LEFT JOIN pg_catalog.pg_roles r ON r.oid = setrole\n",
3859 NULL,
"r.rolname", NULL, NULL, &havewhere, 1))
3862 NULL,
"d.datname", NULL, NULL,
3880 if (pattern && pattern2)
3881 pg_log_error(
"Did not find any settings for role \"%s\" and database \"%s\".",
3884 pg_log_error(
"Did not find any settings for role \"%s\".",
3891 myopt.
title =
_(
"List of settings");
3918 "SELECT m.rolname AS \"%s\", r.rolname AS \"%s\",\n"
3919 " pg_catalog.concat_ws(', ',\n",
3925 " CASE WHEN pam.admin_option THEN 'ADMIN' END,\n"
3926 " CASE WHEN pam.inherit_option THEN 'INHERIT' END,\n"
3927 " CASE WHEN pam.set_option THEN 'SET' END\n");
3930 " CASE WHEN pam.admin_option THEN 'ADMIN' END,\n"
3931 " CASE WHEN m.rolinherit THEN 'INHERIT' END,\n"
3936 " g.rolname AS \"%s\"\n",
3941 "FROM pg_catalog.pg_roles m\n"
3942 " JOIN pg_catalog.pg_auth_members pam ON (pam.member = m.oid)\n"
3943 " LEFT JOIN pg_catalog.pg_roles r ON (pam.roleid = r.oid)\n"
3944 " LEFT JOIN pg_catalog.pg_roles g ON (pam.grantor = g.oid)\n");
3946 if (!showSystem && !pattern)
3950 NULL,
"m.rolname", NULL, NULL,
3964 myopt.
title =
_(
"List of role grants");
3991 bool showTables = strchr(tabtypes,
't') != NULL;
3992 bool showIndexes = strchr(tabtypes,
'i') != NULL;
3993 bool showViews = strchr(tabtypes,
'v') != NULL;
3994 bool showMatViews = strchr(tabtypes,
'm') != NULL;
3995 bool showSeq = strchr(tabtypes,
's') != NULL;
3996 bool showForeign = strchr(tabtypes,
'E') != NULL;
4002 bool translate_columns[] = {
false,
false,
true,
false,
false,
false,
false,
false,
false};
4005 if (!(showTables || showIndexes || showViews || showMatViews || showSeq || showForeign))
4006 showTables = showViews = showMatViews = showSeq = showForeign =
true;
4011 "SELECT n.nspname as \"%s\",\n"
4012 " c.relname as \"%s\",\n"
4020 " WHEN " CppAsString2(RELKIND_FOREIGN_TABLE)
" THEN '%s'"
4021 " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE)
" THEN '%s'"
4022 " WHEN " CppAsString2(RELKIND_PARTITIONED_INDEX)
" THEN '%s'"
4024 " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
4043 ",\n c2.relname as \"%s\"",
4054 ",\n CASE c.relpersistence "
4055 "WHEN " CppAsString2(RELPERSISTENCE_PERMANENT)
" THEN '%s' "
4056 "WHEN " CppAsString2(RELPERSISTENCE_TEMP)
" THEN '%s' "
4057 "WHEN " CppAsString2(RELPERSISTENCE_UNLOGGED)
" THEN '%s' "
4063 translate_columns[cols_so_far] =
true;
4075 (showTables || showMatViews || showIndexes))
4077 ",\n am.amname as \"%s\"",
4081 ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_table_size(c.oid)) as \"%s\""
4082 ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
4088 "\nFROM pg_catalog.pg_class c"
4089 "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
4092 (showTables || showMatViews || showIndexes))
4094 "\n LEFT JOIN pg_catalog.pg_am am ON am.oid = c.relam");
4098 "\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
4099 "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
4107 if (showSystem || pattern)
4119 if (showSystem || pattern)
4127 if (!showSystem && !pattern)
4129 " AND n.nspname !~ '^pg_toast'\n"
4130 " AND n.nspname <> 'information_schema'\n");
4133 "n.nspname",
"c.relname", NULL,
4134 "pg_catalog.pg_table_is_visible(c.oid)",
4156 pg_log_error(
"Did not find any relation named \"%s\".",
4163 myopt.
title =
_(
"List of relations");
4193 bool showTables = strchr(reltypes,
't') != NULL;
4194 bool showIndexes = strchr(reltypes,
'i') != NULL;
4195 bool showNested = strchr(reltypes,
'n') != NULL;
4200 bool translate_columns[] = {
false,
false,
false,
false,
false,
false,
false,
false,
false,
false};
4201 const char *tabletitle;
4202 bool mixed_output =
false;
4211 pg_log_error(
"The server (version %s) does not support declarative table partitioning.",
4213 sverbuf,
sizeof(sverbuf)));
4218 if (!showTables && !showIndexes)
4219 showTables = showIndexes =
true;
4221 if (showIndexes && !showTables)
4222 tabletitle =
_(
"List of partitioned indexes");
4223 else if (showTables && !showIndexes)
4224 tabletitle =
_(
"List of partitioned tables");
4228 tabletitle =
_(
"List of partitioned relations");
4229 mixed_output =
true;
4235 "SELECT n.nspname as \"%s\",\n"
4236 " c.relname as \"%s\",\n"
4237 " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
4245 ",\n CASE c.relkind"
4246 " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE)
" THEN '%s'"
4247 " WHEN " CppAsString2(RELKIND_PARTITIONED_INDEX)
" THEN '%s'"
4253 translate_columns[3] =
true;
4256 if (showNested || pattern)
4258 ",\n inh.inhparent::pg_catalog.regclass as \"%s\"",
4263 ",\n c2.oid::pg_catalog.regclass as \"%s\"",
4278 ",\n s.dps as \"%s\"",
4281 ",\n s.tps as \"%s\"",
4287 ",\n s.tps as \"%s\"",
4291 ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
4296 "\nFROM pg_catalog.pg_class c"
4297 "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
4301 "\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
4302 "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
4304 if (showNested || pattern)
4306 "\n LEFT JOIN pg_catalog.pg_inherits inh ON c.oid = inh.inhrelid");
4311 "\n LEFT JOIN pg_catalog.pg_am am ON c.relam = am.oid");
4316 ",\n LATERAL (WITH RECURSIVE d\n"
4317 " AS (SELECT inhrelid AS oid, 1 AS level\n"
4318 " FROM pg_catalog.pg_inherits\n"
4319 " WHERE inhparent = c.oid\n"
4321 " SELECT inhrelid, level + 1\n"
4322 " FROM pg_catalog.pg_inherits i\n"
4323 " JOIN d ON i.inhparent = d.oid)\n"
4324 " SELECT pg_catalog.pg_size_pretty(sum(pg_catalog.pg_table_size("
4325 "d.oid))) AS tps,\n"
4326 " pg_catalog.pg_size_pretty(sum("
4327 "\n CASE WHEN d.level = 1"
4328 " THEN pg_catalog.pg_table_size(d.oid) ELSE 0 END)) AS dps\n"
4335 ",\n LATERAL (SELECT pg_catalog.pg_size_pretty(sum("
4336 "\n CASE WHEN ppt.isleaf AND ppt.level = 1"
4337 "\n THEN pg_catalog.pg_table_size(ppt.relid)"
4338 " ELSE 0 END)) AS dps"
4339 ",\n pg_catalog.pg_size_pretty(sum("
4340 "pg_catalog.pg_table_size(ppt.relid))) AS tps"
4341 "\n FROM pg_catalog.pg_partition_tree(c.oid) ppt) s");
4354 " AND NOT c.relispartition\n" :
"");
4358 " AND n.nspname !~ '^pg_toast'\n"
4359 " AND n.nspname <> 'information_schema'\n");
4362 "n.nspname",
"c.relname", NULL,
4363 "pg_catalog.pg_table_is_visible(c.oid)",
4371 mixed_output ?
"\"Type\" DESC, " :
"",
4372 showNested || pattern ?
"\"Parent name\" NULLS FIRST, " :
"");
4410 "SELECT l.lanname AS \"%s\",\n"
4411 " pg_catalog.pg_get_userbyid(l.lanowner) as \"%s\",\n"
4412 " l.lanpltrusted AS \"%s\"",
4420 ",\n NOT l.lanispl AS \"%s\",\n"
4421 " l.lanplcallfoid::pg_catalog.regprocedure AS \"%s\",\n"
4422 " l.lanvalidator::pg_catalog.regprocedure AS \"%s\",\n "
4423 "l.laninline::pg_catalog.regprocedure AS \"%s\",\n ",
4432 ",\n d.description AS \"%s\""
4433 "\nFROM pg_catalog.pg_language l\n"
4434 "LEFT JOIN pg_catalog.pg_description d\n"
4435 " ON d.classoid = l.tableoid AND d.objoid = l.oid\n"
4436 " AND d.objsubid = 0\n",
4442 NULL,
"l.lanname", NULL, NULL,
4450 if (!showSystem && !pattern)
4461 myopt.
title =
_(
"List of languages");
4486 "SELECT n.nspname as \"%s\",\n"
4487 " t.typname as \"%s\",\n"
4488 " pg_catalog.format_type(t.typbasetype, t.typtypmod) as \"%s\",\n"
4489 " (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type bt\n"
4490 " WHERE c.oid = t.typcollation AND bt.oid = t.typbasetype AND t.typcollation <> bt.typcollation) as \"%s\",\n"
4491 " CASE WHEN t.typnotnull THEN 'not null' END as \"%s\",\n"
4492 " t.typdefault as \"%s\",\n"
4493 " pg_catalog.array_to_string(ARRAY(\n"
4494 " SELECT pg_catalog.pg_get_constraintdef(r.oid, true) FROM pg_catalog.pg_constraint r WHERE t.oid = r.contypid AND r.contype = " CppAsString2(CONSTRAINT_CHECK)
" ORDER BY r.conname\n"
4495 " ), ' ') as \"%s\"",
4509 ",\n d.description as \"%s\"",
4514 "\nFROM pg_catalog.pg_type t\n"
4515 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
4519 " LEFT JOIN pg_catalog.pg_description d "
4520 "ON d.classoid = t.tableoid AND d.objoid = t.oid "
4521 "AND d.objsubid = 0\n");
4525 if (!showSystem && !pattern)
4527 " AND n.nspname <> 'information_schema'\n");
4530 "n.nspname",
"t.typname", NULL,
4531 "pg_catalog.pg_type_is_visible(t.oid)",
4545 myopt.
title =
_(
"List of domains");
4565 static const bool translate_columns[] =
4566 {
false,
false,
false,
false,
true,
false};
4571 "SELECT n.nspname AS \"%s\",\n"
4572 " c.conname AS \"%s\",\n"
4573 " pg_catalog.pg_encoding_to_char(c.conforencoding) AS \"%s\",\n"
4574 " pg_catalog.pg_encoding_to_char(c.contoencoding) AS \"%s\",\n"
4575 " CASE WHEN c.condefault THEN '%s'\n"
4576 " ELSE '%s' END AS \"%s\"",
4586 ",\n d.description AS \"%s\"",
4590 "\nFROM pg_catalog.pg_conversion c\n"
4591 " JOIN pg_catalog.pg_namespace n "
4592 "ON n.oid = c.connamespace\n");
4596 "LEFT JOIN pg_catalog.pg_description d "
4597 "ON d.classoid = c.tableoid\n"
4598 " AND d.objoid = c.oid "
4599 "AND d.objsubid = 0\n");
4603 if (!showSystem && !pattern)
4605 " AND n.nspname <> 'information_schema'\n");
4608 "n.nspname",
"c.conname", NULL,
4609 "pg_catalog.pg_conversion_is_visible(c.oid)",
4623 myopt.
title =
_(
"List of conversions");
4649 "SELECT s.name AS \"%s\", "
4650 "pg_catalog.current_setting(s.name) AS \"%s\"",
4657 ", s.vartype AS \"%s\", s.context AS \"%s\", ",
4671 " LEFT JOIN pg_catalog.pg_parameter_acl p\n"
4672 " ON pg_catalog.lower(s.name) = p.parname\n");
4677 NULL,
"pg_catalog.lower(s.name)", NULL,
4681 " s.setting IS DISTINCT FROM s.boot_val\n");
4691 myopt.
title =
_(
"List of configuration parameters");
4693 myopt.
title =
_(
"List of non-default configuration parameters");
4713 static const bool translate_columns[] =
4714 {
false,
false,
false,
true,
false,
false,
false};
4720 pg_log_error(
"The server (version %s) does not support event triggers.",
4722 sverbuf,
sizeof(sverbuf)));
4729 "SELECT evtname as \"%s\", "
4730 "evtevent as \"%s\", "
4731 "pg_catalog.pg_get_userbyid(e.evtowner) as \"%s\",\n"
4732 " case evtenabled when 'O' then '%s'"
4733 " when 'R' then '%s'"
4734 " when 'A' then '%s'"
4735 " when 'D' then '%s' end as \"%s\",\n"
4736 " e.evtfoid::pg_catalog.regproc as \"%s\", "
4737 "pg_catalog.array_to_string(array(select x"
4738 " from pg_catalog.unnest(evttags) as t(x)), ', ') as \"%s\"",
4751 ",\npg_catalog.obj_description(e.oid, 'pg_event_trigger') as \"%s\"",
4754 "\nFROM pg_catalog.pg_event_trigger e ");
4757 NULL,
"evtname", NULL, NULL,
4771 myopt.
title =
_(
"List of event triggers");
4798 pg_log_error(
"The server (version %s) does not support extended statistics.",
4800 sverbuf,
sizeof(sverbuf)));
4807 "es.stxnamespace::pg_catalog.regnamespace::pg_catalog.text AS \"%s\", \n"
4808 "es.stxname AS \"%s\", \n",
4814 "pg_catalog.format('%%s FROM %%s', \n"
4815 " pg_catalog.pg_get_statisticsobjdef_columns(es.oid), \n"
4816 " es.stxrelid::pg_catalog.regclass) AS \"%s\"",
4820 "pg_catalog.format('%%s FROM %%s', \n"
4821 " (SELECT pg_catalog.string_agg(pg_catalog.quote_ident(a.attname),', ') \n"
4822 " FROM pg_catalog.unnest(es.stxkeys) s(attnum) \n"
4823 " JOIN pg_catalog.pg_attribute a \n"
4824 " ON (es.stxrelid = a.attrelid \n"
4825 " AND a.attnum = s.attnum \n"
4826 " AND NOT a.attisdropped)), \n"
4827 "es.stxrelid::pg_catalog.regclass) AS \"%s\"",
4831 ",\nCASE WHEN " CppAsString2(STATS_EXT_NDISTINCT)
" = any(es.stxkind) THEN 'defined' \n"
4833 "CASE WHEN " CppAsString2(STATS_EXT_DEPENDENCIES)
" = any(es.stxkind) THEN 'defined' \n"
4844 ",\nCASE WHEN " CppAsString2(STATS_EXT_MCV)
" = any(es.stxkind) THEN 'defined' \n"
4850 " \nFROM pg_catalog.pg_statistic_ext es \n");
4854 "es.stxnamespace::pg_catalog.regnamespace::pg_catalog.text",
"es.stxname",
4855 NULL,
"pg_catalog.pg_statistics_obj_is_visible(es.oid)",
4869 myopt.
title =
_(
"List of extended statistics");
4889 static const bool translate_columns[] = {
false,
false,
false,
true,
false};
4894 "SELECT pg_catalog.format_type(castsource, NULL) AS \"%s\",\n"
4895 " pg_catalog.format_type(casttarget, NULL) AS \"%s\",\n",
4905 " CASE WHEN c.castmethod = '%c' THEN '(binary coercible)'\n"
4906 " WHEN c.castmethod = '%c' THEN '(with inout)'\n"
4908 " END AS \"%s\",\n",
4909 COERCION_METHOD_BINARY,
4910 COERCION_METHOD_INOUT,
4914 " CASE WHEN c.castcontext = '%c' THEN '%s'\n"
4915 " WHEN c.castcontext = '%c' THEN '%s'\n"
4918 COERCION_CODE_EXPLICIT,
4920 COERCION_CODE_ASSIGNMENT,
4927 ",\n d.description AS \"%s\"",
4935 "\nFROM pg_catalog.pg_cast c LEFT JOIN pg_catalog.pg_proc p\n"
4936 " ON c.castfunc = p.oid\n"
4937 " LEFT JOIN pg_catalog.pg_type ts\n"
4938 " ON c.castsource = ts.oid\n"
4939 " LEFT JOIN pg_catalog.pg_namespace ns\n"
4940 " ON ns.oid = ts.typnamespace\n"
4941 " LEFT JOIN pg_catalog.pg_type tt\n"
4942 " ON c.casttarget = tt.oid\n"
4943 " LEFT JOIN pg_catalog.pg_namespace nt\n"
4944 " ON nt.oid = tt.typnamespace\n");
4948 " LEFT JOIN pg_catalog.pg_description d\n"
4949 " ON d.classoid = c.tableoid AND d.objoid = "
4950 "c.oid AND d.objsubid = 0\n");
4959 "ns.nspname",
"ts.typname",
4960 "pg_catalog.format_type(ts.oid, NULL)",
4961 "pg_catalog.pg_type_is_visible(ts.oid)",
4968 "nt.nspname",
"tt.typname",
4969 "pg_catalog.format_type(tt.oid, NULL)",
4970 "pg_catalog.pg_type_is_visible(tt.oid)",
4981 myopt.
title =
_(
"List of casts");
5007 static const bool translate_columns[] = {
false,
false,
false,
false,
false,
false,
false,
true,
false};
5013 " n.nspname AS \"%s\",\n"
5014 " c.collname AS \"%s\",\n",
5020 " CASE c.collprovider "
5021 "WHEN " CppAsString2(COLLPROVIDER_DEFAULT)
" THEN 'default' "
5022 "WHEN " CppAsString2(COLLPROVIDER_BUILTIN)
" THEN 'builtin' "
5023 "WHEN " CppAsString2(COLLPROVIDER_LIBC)
" THEN 'libc' "
5029 " 'libc' AS \"%s\",\n",
5033 " c.collcollate AS \"%s\",\n"
5034 " c.collctype AS \"%s\",\n",
5040 " c.colllocale AS \"%s\",\n",
5044 " c.colliculocale AS \"%s\",\n",
5048 " c.collcollate AS \"%s\",\n",
5053 " c.collicurules AS \"%s\",\n",
5057 " NULL AS \"%s\",\n",
5062 " CASE WHEN c.collisdeterministic THEN '%s' ELSE '%s' END AS \"%s\"",
5073 ",\n pg_catalog.obj_description(c.oid, 'pg_collation') AS \"%s\"",
5077 "\nFROM pg_catalog.pg_collation c, pg_catalog.pg_namespace n\n"
5078 "WHERE n.oid = c.collnamespace\n");
5080 if (!showSystem && !pattern)
5082 " AND n.nspname <> 'information_schema'\n");
5090 appendPQExpBufferStr(&
buf,
" AND c.collencoding IN (-1, pg_catalog.pg_char_to_encoding(pg_catalog.getdatabaseencoding()))\n");
5093 "n.nspname",
"c.collname", NULL,
5094 "pg_catalog.pg_collation_is_visible(c.oid)",
5108 myopt.
title =
_(
"List of collations");
5130 int pub_schema_tuples = 0;
5131 char **footers = NULL;
5135 "SELECT n.nspname AS \"%s\",\n"