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++)
3056 if ((tableinfo.relkind == RELKIND_VIEW ||
3057 tableinfo.relkind == RELKIND_MATVIEW) &&
verbose)
3062 "SELECT pg_catalog.pg_get_viewdef('%s'::pg_catalog.oid, true);",
3083 if (tableinfo.hasrules)
3086 "SELECT r.rulename, trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true))\n"
3087 "FROM pg_catalog.pg_rewrite r\n"
3088 "WHERE r.ev_class = '%s' AND r.rulename != '_RETURN' ORDER BY 1;",
3099 const char *ruledef;
3117 if (tableinfo.hastriggers)
3124 "pg_catalog.pg_get_triggerdef(t.oid, true), "
3125 "t.tgenabled, t.tgisinternal,\n");
3143 " CASE WHEN t.tgparentid != 0 THEN\n"
3144 " (SELECT u.tgrelid::pg_catalog.regclass\n"
3145 " FROM pg_catalog.pg_trigger AS u,\n"
3146 " pg_catalog.pg_partition_ancestors(t.tgrelid) WITH ORDINALITY AS a(relid, depth)\n"
3147 " WHERE u.tgname = t.tgname AND u.tgrelid = a.relid\n"
3148 " AND u.tgparentid = 0\n"
3149 " ORDER BY a.depth LIMIT 1)\n"
3150 " END AS parent\n");
3155 "FROM pg_catalog.pg_trigger t\n"
3156 "WHERE t.tgrelid = '%s' AND ",
3168 " OR EXISTS (SELECT 1 FROM pg_catalog.pg_depend WHERE objid = t.oid \n"
3169 " AND refclassid = 'pg_catalog.pg_trigger'::pg_catalog.regclass))");
3191 for (category = 0; category <= 4; category++)
3193 have_heading =
false;
3194 for (
i = 0;
i < tuples;
i++)
3198 const char *usingpos;
3199 const char *tgenabled;
3200 const char *tgisinternal;
3207 list_trigger =
false;
3211 if (*tgenabled ==
'O' || *tgenabled ==
't')
3212 list_trigger =
true;
3215 if ((*tgenabled ==
'D' || *tgenabled ==
'f') &&
3216 *tgisinternal ==
'f')
3217 list_trigger =
true;
3220 if ((*tgenabled ==
'D' || *tgenabled ==
'f') &&
3221 *tgisinternal ==
't')
3222 list_trigger =
true;
3225 if (*tgenabled ==
'A')
3226 list_trigger =
true;
3229 if (*tgenabled ==
'R')
3230 list_trigger =
true;
3233 if (list_trigger ==
false)
3237 if (have_heading ==
false)
3258 have_heading =
true;
3263 usingpos = strstr(tgdef,
" TRIGGER ");
3265 tgdef = usingpos + 9;
3284 if (tableinfo.relkind == RELKIND_RELATION ||
3285 tableinfo.relkind == RELKIND_MATVIEW ||
3286 tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
3287 tableinfo.relkind == RELKIND_PARTITIONED_TABLE ||
3288 tableinfo.relkind == RELKIND_PARTITIONED_INDEX ||
3289 tableinfo.relkind == RELKIND_TOASTVALUE)
3291 bool is_partitioned;
3296 is_partitioned = (tableinfo.relkind == RELKIND_PARTITIONED_TABLE ||
3297 tableinfo.relkind == RELKIND_PARTITIONED_INDEX);
3300 if (tableinfo.relkind == RELKIND_FOREIGN_TABLE)
3306 "SELECT s.srvname,\n"
3307 " pg_catalog.array_to_string(ARRAY(\n"
3308 " SELECT pg_catalog.quote_ident(option_name)"
3309 " || ' ' || pg_catalog.quote_literal(option_value)\n"
3310 " FROM pg_catalog.pg_options_to_table(ftoptions)), ', ')\n"
3311 "FROM pg_catalog.pg_foreign_table f,\n"
3312 " pg_catalog.pg_foreign_server s\n"
3313 "WHERE f.ftrelid = '%s' AND s.oid = f.ftserver;",
3331 if (ftoptions && ftoptions[0] !=
'\0')
3341 "SELECT c.oid::pg_catalog.regclass\n"
3342 "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n"
3343 "WHERE c.oid = i.inhparent AND i.inhrelid = '%s'\n"
3344 " AND c.relkind != " CppAsString2(RELKIND_PARTITIONED_TABLE)
3345 " AND c.relkind != " CppAsString2(RELKIND_PARTITIONED_INDEX)
3346 "\nORDER BY inhseqno;",
3354 const char *s =
_(
"Inherits");
3359 for (
i = 0;
i < tuples;
i++)
3379 "SELECT c.oid::pg_catalog.regclass, c.relkind,"
3380 " inhdetachpending,"
3381 " pg_catalog.pg_get_expr(c.relpartbound, c.oid)\n"
3382 "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n"
3383 "WHERE c.oid = i.inhrelid AND i.inhparent = '%s'\n"
3384 "ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT',"
3385 " c.oid::pg_catalog.regclass::pg_catalog.text;",
3389 "SELECT c.oid::pg_catalog.regclass, c.relkind,"
3390 " false AS inhdetachpending,"
3391 " pg_catalog.pg_get_expr(c.relpartbound, c.oid)\n"
3392 "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n"
3393 "WHERE c.oid = i.inhrelid AND i.inhparent = '%s'\n"
3394 "ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT',"
3395 " c.oid::pg_catalog.regclass::pg_catalog.text;",
3399 "SELECT c.oid::pg_catalog.regclass, c.relkind,"
3400 " false AS inhdetachpending, NULL\n"
3401 "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n"
3402 "WHERE c.oid = i.inhrelid AND i.inhparent = '%s'\n"
3403 "ORDER BY c.oid::pg_catalog.regclass::pg_catalog.text;",
3417 if (is_partitioned && tuples == 0)
3437 const char *ct = is_partitioned ?
_(
"Partitions") :
_(
"Child tables");
3440 for (
i = 0;
i < tuples;
i++)
3452 if (child_relkind == RELKIND_PARTITIONED_TABLE ||
3453 child_relkind == RELKIND_PARTITIONED_INDEX)
3455 else if (child_relkind == RELKIND_FOREIGN_TABLE)
3468 if (tableinfo.reloftype)
3475 (tableinfo.relkind == RELKIND_RELATION ||
3476 tableinfo.relkind == RELKIND_MATVIEW) &&
3482 tableinfo.relreplident !=
'i' &&
3483 ((strcmp(schemaname,
"pg_catalog") != 0 && tableinfo.relreplident !=
'd') ||
3484 (strcmp(schemaname,
"pg_catalog") == 0 && tableinfo.relreplident !=
'n')))
3486 const char *s =
_(
"Replica Identity");
3490 tableinfo.relreplident ==
'f' ?
"FULL" :
3491 tableinfo.relreplident ==
'n' ?
"NOTHING" :
3498 if (
verbose && tableinfo.relkind != RELKIND_MATVIEW && tableinfo.hasoids)
3515 tableinfo.reloptions && tableinfo.reloptions[0] !=
'\0')
3517 const char *t =
_(
"Options");
3530 if (printTableInitialized)
3553 if (relkind == RELKIND_RELATION ||
3554 relkind == RELKIND_MATVIEW ||
3555 relkind == RELKIND_INDEX ||
3556 relkind == RELKIND_PARTITIONED_TABLE ||
3557 relkind == RELKIND_PARTITIONED_INDEX ||
3558 relkind == RELKIND_TOASTVALUE)
3571 "SELECT spcname FROM pg_catalog.pg_tablespace\n"
3624 const char align =
'l';
3632 "SELECT r.rolname, r.rolsuper, r.rolinherit,\n"
3633 " r.rolcreaterole, r.rolcreatedb, r.rolcanlogin,\n"
3634 " r.rolconnlimit, r.rolvaliduntil,\n"
3635 " ARRAY(SELECT b.rolname\n"
3636 " FROM pg_catalog.pg_auth_members m\n"
3637 " JOIN pg_catalog.pg_roles b ON (m.roleid = b.oid)\n"
3638 " WHERE m.member = r.oid) as memberof");
3654 if (!showSystem && !pattern)
3658 NULL,
"r.rolname", NULL, NULL,
3672 attr =
pg_malloc0((nrows + 1) *
sizeof(*attr));
3684 for (
i = 0;
i < nrows;
i++)
3748 for (
i = 0;
i < nrows;
i++)
3779 "pg_catalog.array_to_string(setconfig, E'\\n') AS \"%s\"",
3787 "LEFT JOIN pg_catalog.pg_database d ON d.oid = setdatabase\n"
3788 "LEFT JOIN pg_catalog.pg_roles r ON r.oid = setrole\n");
3790 NULL,
"r.rolname", NULL, NULL, &havewhere, 1))
3793 NULL,
"d.datname", NULL, NULL,
3811 if (pattern && pattern2)
3812 pg_log_error(
"Did not find any settings for role \"%s\" and database \"%s\".",
3815 pg_log_error(
"Did not find any settings for role \"%s\".",
3823 myopt.
title =
_(
"List of settings");
3855 bool showTables = strchr(tabtypes,
't') != NULL;
3856 bool showIndexes = strchr(tabtypes,
'i') != NULL;
3857 bool showViews = strchr(tabtypes,
'v') != NULL;
3858 bool showMatViews = strchr(tabtypes,
'm') != NULL;
3859 bool showSeq = strchr(tabtypes,
's') != NULL;
3860 bool showForeign = strchr(tabtypes,
'E') != NULL;
3866 bool translate_columns[] = {
false,
false,
true,
false,
false,
false,
false,
false,
false};
3869 if (!(showTables || showIndexes || showViews || showMatViews || showSeq || showForeign))
3870 showTables = showViews = showMatViews = showSeq = showForeign =
true;
3875 "SELECT n.nspname as \"%s\",\n"
3876 " c.relname as \"%s\",\n"
3884 " WHEN " CppAsString2(RELKIND_FOREIGN_TABLE)
" THEN '%s'"
3885 " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE)
" THEN '%s'"
3886 " WHEN " CppAsString2(RELKIND_PARTITIONED_INDEX)
" THEN '%s'"
3888 " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
3907 ",\n c2.relname as \"%s\"",
3918 ",\n CASE c.relpersistence WHEN 'p' THEN '%s' WHEN 't' THEN '%s' WHEN 'u' THEN '%s' END as \"%s\"",
3923 translate_columns[cols_so_far] =
true;
3935 (showTables || showMatViews || showIndexes))
3937 ",\n am.amname as \"%s\"",
3941 ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_table_size(c.oid)) as \"%s\""
3942 ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
3948 "\nFROM pg_catalog.pg_class c"
3949 "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
3952 (showTables || showMatViews || showIndexes))
3954 "\n LEFT JOIN pg_catalog.pg_am am ON am.oid = c.relam");
3958 "\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
3959 "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
3967 if (showSystem || pattern)
3979 if (showSystem || pattern)
3987 if (!showSystem && !pattern)
3989 " AND n.nspname !~ '^pg_toast'\n"
3990 " AND n.nspname <> 'information_schema'\n");
3993 "n.nspname",
"c.relname", NULL,
3994 "pg_catalog.pg_table_is_visible(c.oid)",
4016 pg_log_error(
"Did not find any relation named \"%s\".",
4024 myopt.
title =
_(
"List of relations");
4054 bool showTables = strchr(reltypes,
't') != NULL;
4055 bool showIndexes = strchr(reltypes,
'i') != NULL;
4056 bool showNested = strchr(reltypes,
'n') != NULL;
4061 bool translate_columns[] = {
false,
false,
false,
false,
false,
false,
false,
false,
false};
4062 const char *tabletitle;
4063 bool mixed_output =
false;
4072 pg_log_error(
"The server (version %s) does not support declarative table partitioning.",
4074 sverbuf,
sizeof(sverbuf)));
4079 if (!showTables && !showIndexes)
4080 showTables = showIndexes =
true;
4082 if (showIndexes && !showTables)
4083 tabletitle =
_(
"List of partitioned indexes");
4084 else if (showTables && !showIndexes)
4085 tabletitle =
_(
"List of partitioned tables");
4089 tabletitle =
_(
"List of partitioned relations");
4090 mixed_output =
true;
4096 "SELECT n.nspname as \"%s\",\n"
4097 " c.relname as \"%s\",\n"
4098 " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
4106 ",\n CASE c.relkind"
4107 " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE)
" THEN '%s'"
4108 " WHEN " CppAsString2(RELKIND_PARTITIONED_INDEX)
" THEN '%s'"
4114 translate_columns[3] =
true;
4117 if (showNested || pattern)
4119 ",\n inh.inhparent::pg_catalog.regclass as \"%s\"",
4124 ",\n c2.oid::pg_catalog.regclass as \"%s\"",
4132 ",\n s.dps as \"%s\"",
4135 ",\n s.tps as \"%s\"",
4141 ",\n s.tps as \"%s\"",
4145 ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
4150 "\nFROM pg_catalog.pg_class c"
4151 "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
4155 "\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
4156 "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
4158 if (showNested || pattern)
4160 "\n LEFT JOIN pg_catalog.pg_inherits inh ON c.oid = inh.inhrelid");
4167 ",\n LATERAL (WITH RECURSIVE d\n"
4168 " AS (SELECT inhrelid AS oid, 1 AS level\n"
4169 " FROM pg_catalog.pg_inherits\n"
4170 " WHERE inhparent = c.oid\n"
4172 " SELECT inhrelid, level + 1\n"
4173 " FROM pg_catalog.pg_inherits i\n"
4174 " JOIN d ON i.inhparent = d.oid)\n"
4175 " SELECT pg_catalog.pg_size_pretty(sum(pg_catalog.pg_table_size("
4176 "d.oid))) AS tps,\n"
4177 " pg_catalog.pg_size_pretty(sum("
4178 "\n CASE WHEN d.level = 1"
4179 " THEN pg_catalog.pg_table_size(d.oid) ELSE 0 END)) AS dps\n"
4186 ",\n LATERAL (SELECT pg_catalog.pg_size_pretty(sum("
4187 "\n CASE WHEN ppt.isleaf AND ppt.level = 1"
4188 "\n THEN pg_catalog.pg_table_size(ppt.relid)"
4189 " ELSE 0 END)) AS dps"
4190 ",\n pg_catalog.pg_size_pretty(sum("
4191 "pg_catalog.pg_table_size(ppt.relid))) AS tps"
4192 "\n FROM pg_catalog.pg_partition_tree(c.oid) ppt) s");
4205 " AND NOT c.relispartition\n" :
"");
4209 " AND n.nspname !~ '^pg_toast'\n"
4210 " AND n.nspname <> 'information_schema'\n");
4213 "n.nspname",
"c.relname", NULL,
4214 "pg_catalog.pg_table_is_visible(c.oid)",
4222 mixed_output ?
"\"Type\" DESC, " :
"",
4223 showNested || pattern ?
"\"Parent name\" NULLS FIRST, " :
"");
4262 "SELECT l.lanname AS \"%s\",\n"
4263 " pg_catalog.pg_get_userbyid(l.lanowner) as \"%s\",\n"
4264 " l.lanpltrusted AS \"%s\"",
4272 ",\n NOT l.lanispl AS \"%s\",\n"
4273 " l.lanplcallfoid::pg_catalog.regprocedure AS \"%s\",\n"
4274 " l.lanvalidator::pg_catalog.regprocedure AS \"%s\",\n "
4275 "l.laninline::pg_catalog.regprocedure AS \"%s\",\n ",
4284 ",\n d.description AS \"%s\""
4285 "\nFROM pg_catalog.pg_language l\n"
4286 "LEFT JOIN pg_catalog.pg_description d\n"
4287 " ON d.classoid = l.tableoid AND d.objoid = l.oid\n"
4288 " AND d.objsubid = 0\n",
4294 NULL,
"l.lanname", NULL, NULL,
4302 if (!showSystem && !pattern)
4314 myopt.
title =
_(
"List of languages");
4339 "SELECT n.nspname as \"%s\",\n"
4340 " t.typname as \"%s\",\n"
4341 " pg_catalog.format_type(t.typbasetype, t.typtypmod) as \"%s\",\n"
4342 " (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type bt\n"
4343 " WHERE c.oid = t.typcollation AND bt.oid = t.typbasetype AND t.typcollation <> bt.typcollation) as \"%s\",\n"
4344 " CASE WHEN t.typnotnull THEN 'not null' END as \"%s\",\n"
4345 " t.typdefault as \"%s\",\n"
4346 " pg_catalog.array_to_string(ARRAY(\n"
4347 " SELECT pg_catalog.pg_get_constraintdef(r.oid, true) FROM pg_catalog.pg_constraint r WHERE t.oid = r.contypid\n"
4348 " ), ' ') as \"%s\"",
4362 ",\n d.description as \"%s\"",
4367 "\nFROM pg_catalog.pg_type t\n"
4368 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
4372 " LEFT JOIN pg_catalog.pg_description d "
4373 "ON d.classoid = t.tableoid AND d.objoid = t.oid "
4374 "AND d.objsubid = 0\n");
4378 if (!showSystem && !pattern)
4380 " AND n.nspname <> 'information_schema'\n");
4383 "n.nspname",
"t.typname", NULL,
4384 "pg_catalog.pg_type_is_visible(t.oid)",
4399 myopt.
title =
_(
"List of domains");
4419 static const bool translate_columns[] =
4420 {
false,
false,
false,
false,
true,
false};
4425 "SELECT n.nspname AS \"%s\",\n"
4426 " c.conname AS \"%s\",\n"
4427 " pg_catalog.pg_encoding_to_char(c.conforencoding) AS \"%s\",\n"
4428 " pg_catalog.pg_encoding_to_char(c.contoencoding) AS \"%s\",\n"
4429 " CASE WHEN c.condefault THEN '%s'\n"
4430 " ELSE '%s' END AS \"%s\"",
4440 ",\n d.description AS \"%s\"",
4444 "\nFROM pg_catalog.pg_conversion c\n"
4445 " JOIN pg_catalog.pg_namespace n "
4446 "ON n.oid = c.connamespace\n");
4450 "LEFT JOIN pg_catalog.pg_description d "
4451 "ON d.classoid = c.tableoid\n"
4452 " AND d.objoid = c.oid "
4453 "AND d.objsubid = 0\n");
4457 if (!showSystem && !pattern)
4459 " AND n.nspname <> 'information_schema'\n");
4462 "n.nspname",
"c.conname", NULL,
4463 "pg_catalog.pg_conversion_is_visible(c.oid)",
4478 myopt.
title =
_(
"List of conversions");
4504 "SELECT s.name AS \"%s\", "
4505 "pg_catalog.current_setting(s.name) AS \"%s\"",
4512 ", s.vartype AS \"%s\", s.context AS \"%s\", ",
4526 " LEFT JOIN pg_catalog.pg_parameter_acl p\n"
4527 " ON pg_catalog.lower(s.name) = p.parname\n");
4532 NULL,
"pg_catalog.lower(s.name)", NULL,
4536 " s.setting IS DISTINCT FROM s.boot_val\n");
4547 myopt.
title =
_(
"List of configuration parameters");
4549 myopt.
title =
_(
"List of non-default configuration parameters");
4569 static const bool translate_columns[] =
4570 {
false,
false,
false,
true,
false,
false,
false};
4576 pg_log_error(
"The server (version %s) does not support event triggers.",
4578 sverbuf,
sizeof(sverbuf)));
4585 "SELECT evtname as \"%s\", "
4586 "evtevent as \"%s\", "
4587 "pg_catalog.pg_get_userbyid(e.evtowner) as \"%s\",\n"
4588 " case evtenabled when 'O' then '%s'"
4589 " when 'R' then '%s'"
4590 " when 'A' then '%s'"
4591 " when 'D' then '%s' end as \"%s\",\n"
4592 " e.evtfoid::pg_catalog.regproc as \"%s\", "
4593 "pg_catalog.array_to_string(array(select x"
4594 " from pg_catalog.unnest(evttags) as t(x)), ', ') as \"%s\"",
4607 ",\npg_catalog.obj_description(e.oid, 'pg_event_trigger') as \"%s\"",
4610 "\nFROM pg_catalog.pg_event_trigger e ");
4613 NULL,
"evtname", NULL, NULL,
4628 myopt.
title =
_(
"List of event triggers");
4655 pg_log_error(
"The server (version %s) does not support extended statistics.",
4657 sverbuf,
sizeof(sverbuf)));
4664 "es.stxnamespace::pg_catalog.regnamespace::pg_catalog.text AS \"%s\", \n"
4665 "es.stxname AS \"%s\", \n",
4671 "pg_catalog.format('%%s FROM %%s', \n"
4672 " pg_catalog.pg_get_statisticsobjdef_columns(es.oid), \n"
4673 " es.stxrelid::pg_catalog.regclass) AS \"%s\"",
4677 "pg_catalog.format('%%s FROM %%s', \n"
4678 " (SELECT pg_catalog.string_agg(pg_catalog.quote_ident(a.attname),', ') \n"
4679 " FROM pg_catalog.unnest(es.stxkeys) s(attnum) \n"
4680 " JOIN pg_catalog.pg_attribute a \n"
4681 " ON (es.stxrelid = a.attrelid \n"
4682 " AND a.attnum = s.attnum \n"
4683 " AND NOT a.attisdropped)), \n"
4684 "es.stxrelid::pg_catalog.regclass) AS \"%s\"",
4688 ",\nCASE WHEN 'd' = any(es.stxkind) THEN 'defined' \n"
4690 "CASE WHEN 'f' = any(es.stxkind) THEN 'defined' \n"
4701 ",\nCASE WHEN 'm' = any(es.stxkind) THEN 'defined' \n"
4707 " \nFROM pg_catalog.pg_statistic_ext es \n");
4711 "es.stxnamespace::pg_catalog.regnamespace::pg_catalog.text",
"es.stxname",
4712 NULL,
"pg_catalog.pg_statistics_obj_is_visible(es.oid)",
4727 myopt.
title =
_(
"List of extended statistics");
4747 static const bool translate_columns[] = {
false,
false,
false,
true,
false};
4752 "SELECT pg_catalog.format_type(castsource, NULL) AS \"%s\",\n"
4753 " pg_catalog.format_type(casttarget, NULL) AS \"%s\",\n",
4763 " CASE WHEN c.castmethod = '%c' THEN '(binary coercible)'\n"
4764 " WHEN c.castmethod = '%c' THEN '(with inout)'\n"
4766 " END AS \"%s\",\n",
4767 COERCION_METHOD_BINARY,
4768 COERCION_METHOD_INOUT,
4772 " CASE WHEN c.castcontext = '%c' THEN '%s'\n"
4773 " WHEN c.castcontext = '%c' THEN '%s'\n"
4776 COERCION_CODE_EXPLICIT,
4778 COERCION_CODE_ASSIGNMENT,
4785 ",\n d.description AS \"%s\"",
4793 "\nFROM pg_catalog.pg_cast c LEFT JOIN pg_catalog.pg_proc p\n"
4794 " ON c.castfunc = p.oid\n"
4795 " LEFT JOIN pg_catalog.pg_type ts\n"
4796 " ON c.castsource = ts.oid\n"
4797 " LEFT JOIN pg_catalog.pg_namespace ns\n"
4798 " ON ns.oid = ts.typnamespace\n"
4799 " LEFT JOIN pg_catalog.pg_type tt\n"
4800 " ON c.casttarget = tt.oid\n"
4801 " LEFT JOIN pg_catalog.pg_namespace nt\n"
4802 " ON nt.oid = tt.typnamespace\n");
4806 " LEFT JOIN pg_catalog.pg_description d\n"
4807 " ON d.classoid = c.tableoid AND d.objoid = "
4808 "c.oid AND d.objsubid = 0\n");
4817 "ns.nspname",
"ts.typname",
4818 "pg_catalog.format_type(ts.oid, NULL)",
4819 "pg_catalog.pg_type_is_visible(ts.oid)",
4826 "nt.nspname",
"tt.typname",
4827 "pg_catalog.format_type(tt.oid, NULL)",
4828 "pg_catalog.pg_type_is_visible(tt.oid)",
4840 myopt.
title =
_(
"List of casts");
4866 static const bool translate_columns[] = {
false,
false,
false,
false,
false,
false,
false,
true,
false};
4872 " n.nspname AS \"%s\",\n"
4873 " c.collname AS \"%s\",\n",
4879 " CASE c.collprovider WHEN 'd' THEN 'default' WHEN 'c' THEN 'libc' WHEN 'i' THEN 'icu' END AS \"%s\",\n",
4883 " 'libc' AS \"%s\",\n",
4887 " c.collcollate AS \"%s\",\n"
4888 " c.collctype AS \"%s\",\n",
4894 " c.colliculocale AS \"%s\",\n",
4898 " c.collcollate AS \"%s\",\n",
4903 " c.collicurules AS \"%s\",\n",
4907 " NULL AS \"%s\",\n",
4912 " CASE WHEN c.collisdeterministic THEN '%s' ELSE '%s' END AS \"%s\"",
4923 ",\n pg_catalog.obj_description(c.oid, 'pg_collation') AS \"%s\"",
4927 "\nFROM pg_catalog.pg_collation c, pg_catalog.pg_namespace n\n"
4928 "WHERE n.oid = c.collnamespace\n");
4930 if (!showSystem && !pattern)
4932 " AND n.nspname <> 'information_schema'\n");
4940 appendPQExpBufferStr(&
buf,
" AND c.collencoding IN (-1, pg_catalog.pg_char_to_encoding(pg_catalog.getdatabaseencoding()))\n");
4943 "n.nspname",
"c.collname", NULL,
4944 "pg_catalog.pg_collation_is_visible(c.oid)",
4959 myopt.
title =
_(
"List of collations");
4981 int pub_schema_tuples = 0;
4982 char **footers = NULL;
4986 "SELECT n.nspname AS \"%s\",\n"
4987 " pg_catalog.pg_get_userbyid(n.nspowner) AS \"%s\"",
4996 ",\n pg_catalog.obj_description(n.oid, 'pg_namespace') AS \"%s\"",
5001 "\nFROM pg_catalog.pg_namespace n\n");
5003 if (!showSystem && !pattern)
5005 "WHERE n.nspname !~ '^pg_' AND n.nspname <> 'information_schema'\n");
5008 !showSystem && !pattern,
false,
5009 NULL,
"n.nspname", NULL,
5021 myopt.
title =
_(
"List of schemas");
5031 "FROM pg_catalog.pg_publication p\n"
5032 " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n"
5033 " JOIN pg_catalog.pg_namespace n ON n.oid = pn.pnnspid \n"
5034 "WHERE n.nspname = '%s'\n"
5043 if (pub_schema_tuples > 0)
5050 footers = (
char **)
pg_malloc((1 + pub_schema_tuples + 1) *
sizeof(
char *));
5054 for (
i = 0;
i < pub_schema_tuples;
i++)
5062 footers[
i + 1] = NULL;
5077 char **footer = NULL;
5079 for (footer = footers; *footer; footer++)
5111 " n.nspname as \"%s\",\n"
5112 " p.prsname as \"%s\",\n"
5113 " pg_catalog.obj_description(p.oid, 'pg_ts_parser') as \"%s\"\n"
5114 "FROM pg_catalog.pg_ts_parser p\n"
5115 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.prsnamespace\n",
5122 "n.nspname",
"p.prsname", NULL,
5123 "pg_catalog.pg_ts_parser_is_visible(p.oid)",
5138 myopt.
title =
_(
"List of text search parsers");
5163 "FROM pg_catalog.pg_ts_parser p\n"
5164 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.prsnamespace\n"
5168 "n.nspname",
"p.prsname", NULL,
5169 "pg_catalog.pg_ts_parser_is_visible(p.oid)",