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)",
125 myopt.
title =
_(
"List of aggregate functions");
144 static const bool translate_columns[] = {
false,
true,
false,
false};
150 pg_log_error(
"The server (version %s) does not support access methods.",
152 sverbuf,
sizeof(sverbuf)));
159 "SELECT amname AS \"%s\",\n"
161 " WHEN 'i' THEN '%s'"
162 " WHEN 't' THEN '%s'"
172 ",\n amhandler AS \"%s\",\n"
173 " pg_catalog.obj_description(oid, 'pg_am') AS \"%s\"",
179 "\nFROM pg_catalog.pg_am\n");
182 NULL,
"amname", NULL,
195 myopt.
title =
_(
"List of access methods");
220 "SELECT spcname AS \"%s\",\n"
221 " pg_catalog.pg_get_userbyid(spcowner) AS \"%s\",\n"
222 " pg_catalog.pg_tablespace_location(oid) AS \"%s\"",
232 ",\n spcoptions AS \"%s\""
233 ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_tablespace_size(oid)) AS \"%s\""
234 ",\n pg_catalog.shobj_description(oid, 'pg_tablespace') AS \"%s\"",
241 "\nFROM pg_catalog.pg_tablespace\n");
244 NULL,
"spcname", NULL,
257 myopt.
title =
_(
"List of tablespaces");
283 char **arg_patterns,
int num_arg_patterns,
286 bool showAggregate = strchr(functypes,
'a') != NULL;
287 bool showNormal = strchr(functypes,
'n') != NULL;
288 bool showProcedure = strchr(functypes,
'p') != NULL;
289 bool showTrigger = strchr(functypes,
't') != NULL;
290 bool showWindow = strchr(functypes,
'w') != NULL;
295 static const bool translate_columns[] = {
false,
false,
false,
false,
true,
true,
true,
false,
true,
false,
false,
false,
false};
298 static const bool translate_columns_pre_96[] = {
false,
false,
false,
false,
true,
true,
false,
true,
false,
false,
false,
false};
300 if (strlen(functypes) != strspn(functypes,
"anptwS+"))
310 pg_log_error(
"\\df does not take a \"%c\" option with server version %s",
313 sverbuf,
sizeof(sverbuf)));
317 if (!showAggregate && !showNormal && !showProcedure && !showTrigger && !showWindow)
319 showAggregate = showNormal = showTrigger = showWindow =
true;
321 showProcedure =
true;
327 "SELECT n.nspname as \"%s\",\n"
328 " p.proname as \"%s\",\n",
334 " pg_catalog.pg_get_function_result(p.oid) as \"%s\",\n"
335 " pg_catalog.pg_get_function_arguments(p.oid) as \"%s\",\n"
337 " WHEN 'a' THEN '%s'\n"
338 " WHEN 'w' THEN '%s'\n"
339 " WHEN 'p' THEN '%s'\n"
352 " pg_catalog.pg_get_function_result(p.oid) as \"%s\",\n"
353 " pg_catalog.pg_get_function_arguments(p.oid) as \"%s\",\n"
355 " WHEN p.proisagg THEN '%s'\n"
356 " WHEN p.proiswindow THEN '%s'\n"
357 " WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN '%s'\n"
373 " WHEN p.provolatile = 'i' THEN '%s'\n"
374 " WHEN p.provolatile = 's' THEN '%s'\n"
375 " WHEN p.provolatile = 'v' THEN '%s'\n"
384 " WHEN p.proparallel = 'r' THEN '%s'\n"
385 " WHEN p.proparallel = 's' THEN '%s'\n"
386 " WHEN p.proparallel = 'u' THEN '%s'\n"
393 ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\""
394 ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\"",
402 ",\n l.lanname as \"%s\"",
406 ",\n COALESCE(pg_catalog.pg_get_function_sqlbody(p.oid), p.prosrc) as \"%s\"",
410 ",\n p.prosrc as \"%s\"",
413 ",\n pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"",
418 "\nFROM pg_catalog.pg_proc p"
419 "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n");
421 for (
int i = 0;
i < num_arg_patterns;
i++)
424 " LEFT JOIN pg_catalog.pg_type t%d ON t%d.oid = p.proargtypes[%d]\n"
425 " LEFT JOIN pg_catalog.pg_namespace nt%d ON nt%d.oid = t%d.typnamespace\n",
431 " LEFT JOIN pg_catalog.pg_language l ON l.oid = p.prolang\n");
436 if (showNormal && showAggregate && showProcedure && showTrigger && showWindow)
493 bool needs_or =
false;
511 "p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype\n");
534 "n.nspname",
"p.proname", NULL,
535 "pg_catalog.pg_function_is_visible(p.oid)",
539 for (
int i = 0;
i < num_arg_patterns;
i++)
541 if (strcmp(arg_patterns[
i],
"-") != 0)
553 snprintf(nspname,
sizeof(nspname),
"nt%d.nspname",
i);
556 "pg_catalog.format_type(t%d.oid, NULL)",
i);
558 "pg_catalog.pg_type_is_visible(t%d.oid)",
i);
573 if (!showSystem && !func_pattern)
575 " AND n.nspname <> 'information_schema'\n");
585 myopt.
title =
_(
"List of functions");
620 "SELECT n.nspname as \"%s\",\n"
621 " pg_catalog.format_type(t.oid, NULL) AS \"%s\",\n",
627 " t.typname AS \"%s\",\n"
628 " CASE WHEN t.typrelid != 0\n"
629 " THEN CAST('tuple' AS pg_catalog.text)\n"
630 " WHEN t.typlen < 0\n"
631 " THEN CAST('var' AS pg_catalog.text)\n"
632 " ELSE CAST(t.typlen AS pg_catalog.text)\n"
634 " pg_catalog.array_to_string(\n"
636 " SELECT e.enumlabel\n"
637 " FROM pg_catalog.pg_enum e\n"
638 " WHERE e.enumtypid = t.oid\n"
639 " ORDER BY e.enumsortorder\n"
643 " pg_catalog.pg_get_userbyid(t.typowner) AS \"%s\",\n",
653 " pg_catalog.obj_description(t.oid, 'pg_type') as \"%s\"\n",
657 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
665 " FROM pg_catalog.pg_class c "
666 "WHERE c.oid = t.typrelid))\n");
671 if (pattern == NULL || strstr(pattern,
"[]") == NULL)
672 appendPQExpBufferStr(&
buf,
" AND NOT EXISTS(SELECT 1 FROM pg_catalog.pg_type el WHERE el.oid = t.typelem AND el.typarray = t.oid)\n");
674 if (!showSystem && !pattern)
676 " AND n.nspname <> 'information_schema'\n");
681 "n.nspname",
"t.typname",
682 "pg_catalog.format_type(t.oid, NULL)",
683 "pg_catalog.pg_type_is_visible(t.oid)",
695 myopt.
title =
_(
"List of data types");
716 static const char *
const typename_map[] = {
722 "decimal",
"numeric",
723 "float",
"double precision",
730 "bool[]",
"boolean[]",
731 "decimal[]",
"numeric[]",
732 "float[]",
"double precision[]",
733 "float4[]",
"real[]",
734 "float8[]",
"double precision[]",
735 "int[]",
"integer[]",
736 "int2[]",
"smallint[]",
737 "int4[]",
"integer[]",
738 "int8[]",
"bigint[]",
739 "time[]",
"time without time zone[]",
740 "timetz[]",
"time with time zone[]",
741 "timestamp[]",
"timestamp without time zone[]",
742 "timestamptz[]",
"timestamp with time zone[]",
743 "varbit[]",
"bit varying[]",
744 "varchar[]",
"character varying[]",
750 for (
int i = 0; typename_map[
i] != NULL;
i += 2)
753 return typename_map[
i + 1];
765 char **arg_patterns,
int num_arg_patterns,
791 "SELECT n.nspname as \"%s\",\n"
792 " o.oprname AS \"%s\",\n"
793 " CASE WHEN o.oprkind='l' THEN NULL ELSE pg_catalog.format_type(o.oprleft, NULL) END AS \"%s\",\n"
794 " CASE WHEN o.oprkind='r' THEN NULL ELSE pg_catalog.format_type(o.oprright, NULL) END AS \"%s\",\n"
795 " pg_catalog.format_type(o.oprresult, NULL) AS \"%s\",\n",
804 " o.oprcode AS \"%s\",\n",
808 " coalesce(pg_catalog.obj_description(o.oid, 'pg_operator'),\n"
809 " pg_catalog.obj_description(o.oprcode, 'pg_proc')) AS \"%s\"\n"
810 "FROM pg_catalog.pg_operator o\n"
811 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = o.oprnamespace\n",
814 if (num_arg_patterns >= 2)
816 num_arg_patterns = 2;
818 " LEFT JOIN pg_catalog.pg_type t0 ON t0.oid = o.oprleft\n"
819 " LEFT JOIN pg_catalog.pg_namespace nt0 ON nt0.oid = t0.typnamespace\n"
820 " LEFT JOIN pg_catalog.pg_type t1 ON t1.oid = o.oprright\n"
821 " LEFT JOIN pg_catalog.pg_namespace nt1 ON nt1.oid = t1.typnamespace\n");
823 else if (num_arg_patterns == 1)
826 " LEFT JOIN pg_catalog.pg_type t0 ON t0.oid = o.oprright\n"
827 " LEFT JOIN pg_catalog.pg_namespace nt0 ON nt0.oid = t0.typnamespace\n");
830 if (!showSystem && !oper_pattern)
832 " AND n.nspname <> 'information_schema'\n");
835 !showSystem && !oper_pattern,
true,
836 "n.nspname",
"o.oprname", NULL,
837 "pg_catalog.pg_operator_is_visible(o.oid)",
841 if (num_arg_patterns == 1)
844 for (
int i = 0;
i < num_arg_patterns;
i++)
846 if (strcmp(arg_patterns[
i],
"-") != 0)
858 snprintf(nspname,
sizeof(nspname),
"nt%d.nspname",
i);
861 "pg_catalog.format_type(t%d.oid, NULL)",
i);
863 "pg_catalog.pg_type_is_visible(t%d.oid)",
i);
886 myopt.
title =
_(
"List of operators");
911 "SELECT d.datname as \"%s\",\n"
912 " pg_catalog.pg_get_userbyid(d.datdba) as \"%s\",\n"
913 " pg_catalog.pg_encoding_to_char(d.encoding) as \"%s\",\n"
914 " d.datcollate as \"%s\",\n"
915 " d.datctype as \"%s\",\n",
923 " d.daticulocale as \"%s\",\n"
924 " CASE d.datlocprovider WHEN 'c' THEN 'libc' WHEN 'i' THEN 'icu' END AS \"%s\",\n",
930 " 'libc' AS \"%s\",\n",
937 ",\n CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT')\n"
938 " THEN pg_catalog.pg_size_pretty(pg_catalog.pg_database_size(d.datname))\n"
939 " ELSE 'No Access'\n"
941 ",\n t.spcname as \"%s\""
942 ",\n pg_catalog.shobj_description(d.oid, 'pg_database') as \"%s\"",
947 "\nFROM pg_catalog.pg_database d\n");
950 " JOIN pg_catalog.pg_tablespace t on d.dattablespace = t.oid\n");
954 NULL,
"d.datname", NULL, NULL,
965 myopt.
title =
_(
"List of databases");
985 static const bool translate_columns[] = {
false,
false,
true,
false,
false,
false};
993 "SELECT n.nspname as \"%s\",\n"
994 " c.relname as \"%s\",\n"
1000 " WHEN " CppAsString2(RELKIND_FOREIGN_TABLE)
" THEN '%s'"
1001 " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE)
" THEN '%s'"
1017 ",\n pg_catalog.array_to_string(ARRAY(\n"
1018 " SELECT attname || E':\\n ' || pg_catalog.array_to_string(attacl, E'\\n ')\n"
1019 " FROM pg_catalog.pg_attribute a\n"
1020 " WHERE attrelid = c.oid AND NOT attisdropped AND attacl IS NOT NULL\n"
1021 " ), E'\\n') AS \"%s\"",
1026 ",\n pg_catalog.array_to_string(ARRAY(\n"
1028 " || CASE WHEN polcmd != '*' THEN\n"
1029 " E' (' || polcmd::pg_catalog.text || E'):'\n"
1032 " || CASE WHEN polqual IS NOT NULL THEN\n"
1033 " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n"
1036 " || CASE WHEN polwithcheck IS NOT NULL THEN\n"
1037 " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n"
1040 " || CASE WHEN polroles <> '{0}' THEN\n"
1041 " E'\\n to: ' || pg_catalog.array_to_string(\n"
1044 " FROM pg_catalog.pg_roles\n"
1045 " WHERE oid = ANY (polroles)\n"
1050 " FROM pg_catalog.pg_policy pol\n"
1051 " WHERE polrelid = c.oid), E'\\n')\n"
1057 ",\n pg_catalog.array_to_string(ARRAY(\n"
1059 " || CASE WHEN NOT polpermissive THEN\n"
1060 " E' (RESTRICTIVE)'\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"
1090 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
1091 "WHERE c.relkind IN ("
1106 "n.nspname",
"c.relname", NULL,
1107 "n.nspname !~ '^pg_' AND pg_catalog.pg_table_is_visible(c.oid)",
1146 static const bool translate_columns[] = {
false,
false,
true,
false};
1151 "SELECT pg_catalog.pg_get_userbyid(d.defaclrole) AS \"%s\",\n"
1152 " n.nspname AS \"%s\",\n"
1153 " 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"
1165 DEFACLOBJ_NAMESPACE,
1172 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.defaclnamespace\n");
1177 "pg_catalog.pg_get_userbyid(d.defaclrole)",
1223 static const bool translate_columns[] = {
false,
false,
true,
false};
1228 "SELECT DISTINCT tt.nspname AS \"%s\", tt.name AS \"%s\", tt.object AS \"%s\", d.description AS \"%s\"\n"
1237 " SELECT pgc.oid as oid, pgc.tableoid AS tableoid,\n"
1238 " n.nspname as nspname,\n"
1239 " CAST(pgc.conname AS pg_catalog.text) as name,"
1240 " CAST('%s' AS pg_catalog.text) as object\n"
1241 " FROM pg_catalog.pg_constraint pgc\n"
1242 " JOIN pg_catalog.pg_class c "
1243 "ON c.oid = pgc.conrelid\n"
1244 " LEFT JOIN pg_catalog.pg_namespace n "
1245 " ON n.oid = c.relnamespace\n",
1248 if (!showSystem && !pattern)
1250 " AND n.nspname <> 'information_schema'\n");
1253 false,
"n.nspname",
"pgc.conname", NULL,
1254 "pg_catalog.pg_table_is_visible(c.oid)",
1261 " SELECT pgc.oid as oid, pgc.tableoid AS tableoid,\n"
1262 " n.nspname as nspname,\n"
1263 " CAST(pgc.conname AS pg_catalog.text) as name,"
1264 " CAST('%s' AS pg_catalog.text) as object\n"
1265 " FROM pg_catalog.pg_constraint pgc\n"
1266 " JOIN pg_catalog.pg_type t "
1267 "ON t.oid = pgc.contypid\n"
1268 " LEFT JOIN pg_catalog.pg_namespace n "
1269 " ON n.oid = t.typnamespace\n",
1272 if (!showSystem && !pattern)
1274 " AND n.nspname <> 'information_schema'\n");
1277 false,
"n.nspname",
"pgc.conname", NULL,
1278 "pg_catalog.pg_type_is_visible(t.oid)",
1285 " SELECT o.oid as oid, o.tableoid as tableoid,\n"
1286 " n.nspname as nspname,\n"
1287 " CAST(o.opcname AS pg_catalog.text) as name,\n"
1288 " CAST('%s' AS pg_catalog.text) as object\n"
1289 " FROM pg_catalog.pg_opclass o\n"
1290 " JOIN pg_catalog.pg_am am ON "
1291 "o.opcmethod = am.oid\n"
1292 " JOIN pg_catalog.pg_namespace n ON "
1293 "n.oid = o.opcnamespace\n",
1296 if (!showSystem && !pattern)
1298 " AND n.nspname <> 'information_schema'\n");
1301 "n.nspname",
"o.opcname", NULL,
1302 "pg_catalog.pg_opclass_is_visible(o.oid)",
1309 " SELECT opf.oid as oid, opf.tableoid as tableoid,\n"
1310 " n.nspname as nspname,\n"
1311 " CAST(opf.opfname AS pg_catalog.text) AS name,\n"
1312 " CAST('%s' AS pg_catalog.text) as object\n"
1313 " FROM pg_catalog.pg_opfamily opf\n"
1314 " JOIN pg_catalog.pg_am am "
1315 "ON opf.opfmethod = am.oid\n"
1316 " JOIN pg_catalog.pg_namespace n "
1317 "ON opf.opfnamespace = n.oid\n",
1320 if (!showSystem && !pattern)
1322 " AND n.nspname <> 'information_schema'\n");
1325 "n.nspname",
"opf.opfname", NULL,
1326 "pg_catalog.pg_opfamily_is_visible(opf.oid)",
1333 " SELECT r.oid as oid, r.tableoid as tableoid,\n"
1334 " n.nspname as nspname,\n"
1335 " CAST(r.rulename AS pg_catalog.text) as name,"
1336 " CAST('%s' AS pg_catalog.text) as object\n"
1337 " FROM pg_catalog.pg_rewrite r\n"
1338 " JOIN pg_catalog.pg_class c ON c.oid = r.ev_class\n"
1339 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
1340 " WHERE r.rulename != '_RETURN'\n",
1343 if (!showSystem && !pattern)
1345 " AND n.nspname <> 'information_schema'\n");
1348 "n.nspname",
"r.rulename", NULL,
1349 "pg_catalog.pg_table_is_visible(c.oid)",
1356 " SELECT t.oid as oid, t.tableoid as tableoid,\n"
1357 " n.nspname as nspname,\n"
1358 " CAST(t.tgname AS pg_catalog.text) as name,"
1359 " CAST('%s' AS pg_catalog.text) as object\n"
1360 " FROM pg_catalog.pg_trigger t\n"
1361 " JOIN pg_catalog.pg_class c ON c.oid = t.tgrelid\n"
1362 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n",
1365 if (!showSystem && !pattern)
1367 " AND n.nspname <> 'information_schema'\n");
1370 "n.nspname",
"t.tgname", NULL,
1371 "pg_catalog.pg_table_is_visible(c.oid)",
1377 " JOIN pg_catalog.pg_description d ON (tt.oid = d.objoid AND tt.tableoid = d.classoid AND d.objsubid = 0)\n");
1387 myopt.
title =
_(
"Object descriptions");
1420 "FROM pg_catalog.pg_class c\n"
1421 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n");
1423 if (!showSystem && !pattern)
1425 " AND n.nspname <> 'information_schema'\n");
1428 "n.nspname",
"c.relname", NULL,
1429 "pg_catalog.pg_table_is_visible(c.oid)",
1445 pg_log_error(
"Did not find any relation named \"%s\".",
1457 const char *nspname;
1489 const char *relationname,
1493 bool retval =
false;
1498 bool printTableInitialized =
false;
1500 char *view_def = NULL;
1505 int attname_col = -1,
1508 attnotnull_col = -1,
1510 attidentity_col = -1,
1511 attgenerated_col = -1,
1512 isindexkey_col = -1,
1515 attstorage_col = -1,
1516 attcompression_col = -1,
1517 attstattarget_col = -1,
1528 bool forcerowsecurity;
1534 char relpersistence;
1538 bool show_column_details =
false;
1552 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1553 "c.relhastriggers, c.relrowsecurity, c.relforcerowsecurity, "
1554 "false AS relhasoids, c.relispartition, %s, c.reltablespace, "
1555 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
1556 "c.relpersistence, c.relreplident, am.amname\n"
1557 "FROM pg_catalog.pg_class c\n "
1558 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1559 "LEFT JOIN pg_catalog.pg_am am ON (c.relam = am.oid)\n"
1560 "WHERE c.oid = '%s';",
1562 "pg_catalog.array_to_string(c.reloptions || "
1563 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1570 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1571 "c.relhastriggers, c.relrowsecurity, c.relforcerowsecurity, "
1572 "c.relhasoids, c.relispartition, %s, c.reltablespace, "
1573 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
1574 "c.relpersistence, c.relreplident\n"
1575 "FROM pg_catalog.pg_class c\n "
1576 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1577 "WHERE c.oid = '%s';",
1579 "pg_catalog.array_to_string(c.reloptions || "
1580 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1587 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1588 "c.relhastriggers, c.relrowsecurity, c.relforcerowsecurity, "
1589 "c.relhasoids, false as relispartition, %s, c.reltablespace, "
1590 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
1591 "c.relpersistence, c.relreplident\n"
1592 "FROM pg_catalog.pg_class c\n "
1593 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1594 "WHERE c.oid = '%s';",
1596 "pg_catalog.array_to_string(c.reloptions || "
1597 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1604 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1605 "c.relhastriggers, false, false, c.relhasoids, "
1606 "false as relispartition, %s, c.reltablespace, "
1607 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
1608 "c.relpersistence, c.relreplident\n"
1609 "FROM pg_catalog.pg_class c\n "
1610 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1611 "WHERE c.oid = '%s';",
1613 "pg_catalog.array_to_string(c.reloptions || "
1614 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1621 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1622 "c.relhastriggers, false, false, c.relhasoids, "
1623 "false as relispartition, %s, c.reltablespace, "
1624 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
1625 "c.relpersistence\n"
1626 "FROM pg_catalog.pg_class c\n "
1627 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1628 "WHERE c.oid = '%s';",
1630 "pg_catalog.array_to_string(c.reloptions || "
1631 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1644 pg_log_error(
"Did not find any relation with OID %s.", oid);
1650 tableinfo.hasindex = strcmp(
PQgetvalue(
res, 0, 2),
"t") == 0;
1651 tableinfo.hasrules = strcmp(
PQgetvalue(
res, 0, 3),
"t") == 0;
1652 tableinfo.hastriggers = strcmp(
PQgetvalue(
res, 0, 4),
"t") == 0;
1653 tableinfo.rowsecurity = strcmp(
PQgetvalue(
res, 0, 5),
"t") == 0;
1654 tableinfo.forcerowsecurity = strcmp(
PQgetvalue(
res, 0, 6),
"t") == 0;
1655 tableinfo.hasoids = strcmp(
PQgetvalue(
res, 0, 7),
"t") == 0;
1656 tableinfo.ispartition = strcmp(
PQgetvalue(
res, 0, 8),
"t") == 0;
1659 tableinfo.reloftype = (strcmp(
PQgetvalue(
res, 0, 11),
"") != 0) ?
1668 tableinfo.relam = NULL;
1675 if (tableinfo.relkind == RELKIND_SEQUENCE)
1679 char *footers[2] = {NULL, NULL};
1684 "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n"
1685 " seqstart AS \"%s\",\n"
1686 " seqmin AS \"%s\",\n"
1687 " seqmax AS \"%s\",\n"
1688 " seqincrement AS \"%s\",\n"
1689 " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n"
1690 " seqcache AS \"%s\"\n",
1701 "FROM pg_catalog.pg_sequence\n"
1702 "WHERE seqrelid = '%s';",
1708 "SELECT 'bigint' AS \"%s\",\n"
1709 " start_value AS \"%s\",\n"
1710 " min_value AS \"%s\",\n"
1711 " max_value AS \"%s\",\n"
1712 " increment_by AS \"%s\",\n"
1713 " CASE WHEN is_cycled THEN '%s' ELSE '%s' END AS \"%s\",\n"
1714 " cache_value AS \"%s\"\n",
1735 "\n pg_catalog.quote_ident(relname) || '.' ||"
1736 "\n pg_catalog.quote_ident(attname),"
1738 "\nFROM pg_catalog.pg_class c"
1739 "\nINNER JOIN pg_catalog.pg_depend d ON c.oid=d.refobjid"
1740 "\nINNER JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace"
1741 "\nINNER JOIN pg_catalog.pg_attribute a ON ("
1742 "\n a.attrelid=c.oid AND"
1743 "\n a.attnum=d.refobjsubid)"
1744 "\nWHERE d.classid='pg_catalog.pg_class'::pg_catalog.regclass"
1745 "\n AND d.refclassid='pg_catalog.pg_class'::pg_catalog.regclass"
1746 "\n AND d.objid='%s'"
1747 "\n AND d.deptype IN ('a', 'i')",
1764 footers[0] =
psprintf(
_(
"Owned by: %s"),
1768 footers[0] =
psprintf(
_(
"Sequence for identity column: %s"),
1775 if (tableinfo.relpersistence ==
'u')
1777 schemaname, relationname);
1780 schemaname, relationname);
1797 if (tableinfo.relkind == RELKIND_RELATION ||
1798 tableinfo.relkind == RELKIND_VIEW ||
1799 tableinfo.relkind == RELKIND_MATVIEW ||
1800 tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
1801 tableinfo.relkind == RELKIND_COMPOSITE_TYPE ||
1802 tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
1803 show_column_details =
true;
1815 attname_col = cols++;
1817 atttype_col = cols++;
1819 if (show_column_details)
1823 ",\n (SELECT pg_catalog.pg_get_expr(d.adbin, d.adrelid, true)"
1824 "\n FROM pg_catalog.pg_attrdef d"
1825 "\n WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef)"
1826 ",\n a.attnotnull");
1827 attrdef_col = cols++;
1828 attnotnull_col = cols++;
1830 " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation");
1831 attcoll_col = cols++;
1836 attidentity_col = cols++;
1841 attgenerated_col = cols++;
1843 if (tableinfo.relkind == RELKIND_INDEX ||
1844 tableinfo.relkind == RELKIND_PARTITIONED_INDEX)
1848 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",
1852 isindexkey_col = cols++;
1855 indexdef_col = cols++;
1858 if (tableinfo.relkind == RELKIND_FOREIGN_TABLE)
1861 " '(' || pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(option_name) || ' ' || pg_catalog.quote_literal(option_value) FROM "
1862 " pg_catalog.pg_options_to_table(attfdwoptions)), ', ') || ')' END AS attfdwoptions");
1863 fdwopts_col = cols++;
1868 attstorage_col = cols++;
1873 (tableinfo.relkind == RELKIND_RELATION ||
1874 tableinfo.relkind == RELKIND_PARTITIONED_TABLE ||
1875 tableinfo.relkind == RELKIND_MATVIEW))
1878 attcompression_col = cols++;
1882 if (tableinfo.relkind == RELKIND_RELATION ||
1883 tableinfo.relkind == RELKIND_INDEX ||
1884 tableinfo.relkind == RELKIND_PARTITIONED_INDEX ||
1885 tableinfo.relkind == RELKIND_MATVIEW ||
1886 tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
1887 tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
1889 appendPQExpBufferStr(&
buf,
",\n CASE WHEN a.attstattarget=-1 THEN NULL ELSE a.attstattarget END AS attstattarget");
1890 attstattarget_col = cols++;
1897 if (tableinfo.relkind == RELKIND_RELATION ||
1898 tableinfo.relkind == RELKIND_VIEW ||
1899 tableinfo.relkind == RELKIND_MATVIEW ||
1900 tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
1901 tableinfo.relkind == RELKIND_COMPOSITE_TYPE ||
1902 tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
1905 attdescr_col = cols++;
1910 appendPQExpBuffer(&
buf,
"\nWHERE a.attrelid = '%s' AND a.attnum > 0 AND NOT a.attisdropped", oid);
1919 switch (tableinfo.relkind)
1921 case RELKIND_RELATION:
1922 if (tableinfo.relpersistence ==
'u')
1924 schemaname, relationname);
1927 schemaname, relationname);
1931 schemaname, relationname);
1933 case RELKIND_MATVIEW:
1934 if (tableinfo.relpersistence ==
'u')
1936 schemaname, relationname);
1939 schemaname, relationname);
1942 if (tableinfo.relpersistence ==
'u')
1944 schemaname, relationname);
1947 schemaname, relationname);
1949 case RELKIND_PARTITIONED_INDEX:
1950 if (tableinfo.relpersistence ==
'u')
1952 schemaname, relationname);
1955 schemaname, relationname);
1957 case RELKIND_TOASTVALUE:
1959 schemaname, relationname);
1961 case RELKIND_COMPOSITE_TYPE:
1963 schemaname, relationname);
1965 case RELKIND_FOREIGN_TABLE:
1967 schemaname, relationname);
1969 case RELKIND_PARTITIONED_TABLE:
1970 if (tableinfo.relpersistence ==
'u')
1972 schemaname, relationname);
1975 schemaname, relationname);
1980 tableinfo.relkind, schemaname, relationname);
1988 if (show_column_details)
1994 if (isindexkey_col >= 0)
1996 if (indexdef_col >= 0)
1998 if (fdwopts_col >= 0)
2000 if (attstorage_col >= 0)
2002 if (attcompression_col >= 0)
2004 if (attstattarget_col >= 0)
2006 if (attdescr_col >= 0)
2012 printTableInitialized =
true;
2014 for (
i = 0;
i < cols;
i++)
2018 for (
i = 0;
i < numrows;
i++)
2027 if (show_column_details)
2032 bool mustfree =
false;
2037 strcmp(
PQgetvalue(
res,
i, attnotnull_col),
"t") == 0 ?
"not null" :
"",
2043 if (identity[0] == ATTRIBUTE_IDENTITY_ALWAYS)
2044 default_str =
"generated always as identity";
2045 else if (identity[0] == ATTRIBUTE_IDENTITY_BY_DEFAULT)
2046 default_str =
"generated by default as identity";
2047 else if (generated[0] == ATTRIBUTE_GENERATED_STORED)
2049 default_str =
psprintf(
"generated always as (%s) stored",
2060 if (isindexkey_col >= 0)
2062 if (indexdef_col >= 0)
2066 if (fdwopts_col >= 0)
2070 if (attstorage_col >= 0)
2076 (storage[0] ==
'm' ?
"main" :
2077 (storage[0] ==
'x' ?
"extended" :
2078 (storage[0] ==
'e' ?
"external" :
2084 if (attcompression_col >= 0)
2090 (compression[0] ==
'l' ?
"lz4" :
2091 (compression[0] ==
'\0' ?
"" :
2097 if (attstattarget_col >= 0)
2102 if (attdescr_col >= 0)
2109 if (tableinfo.ispartition)
2115 "SELECT inhparent::pg_catalog.regclass,\n"
2116 " pg_catalog.pg_get_expr(c.relpartbound, c.oid),\n ");
2120 "false as inhdetachpending");
2125 ",\n pg_catalog.pg_get_partition_constraintdef(c.oid)");
2127 "\nFROM pg_catalog.pg_class c"
2128 " JOIN pg_catalog.pg_inherits i"
2129 " ON c.oid = inhrelid"
2130 "\nWHERE c.oid = '%s';", oid);
2137 char *parent_name =
PQgetvalue(result, 0, 0);
2143 strcmp(detached,
"t") == 0 ?
" DETACH PENDING" :
"");
2148 char *partconstraintdef = NULL;
2151 partconstraintdef =
PQgetvalue(result, 0, 3);
2153 if (partconstraintdef == NULL || partconstraintdef[0] ==
'\0')
2164 if (tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
2170 "SELECT pg_catalog.pg_get_partkeydef('%s'::pg_catalog.oid);",
2186 if (tableinfo.relkind == RELKIND_TOASTVALUE)
2192 "SELECT n.nspname, c.relname\n"
2193 "FROM pg_catalog.pg_class c"
2194 " JOIN pg_catalog.pg_namespace n"
2195 " ON n.oid = c.relnamespace\n"
2196 "WHERE reltoastrelid = '%s';", oid);
2213 if (tableinfo.relkind == RELKIND_INDEX ||
2214 tableinfo.relkind == RELKIND_PARTITIONED_INDEX)
2220 "SELECT i.indisunique, i.indisprimary, i.indisclustered, "
2222 " (NOT i.indimmediate) AND "
2223 "EXISTS (SELECT 1 FROM pg_catalog.pg_constraint "
2224 "WHERE conrelid = i.indrelid AND "
2225 "conindid = i.indexrelid AND "
2226 "contype IN ('p','u','x') AND "
2227 "condeferrable) AS condeferrable,\n"
2228 " (NOT i.indimmediate) AND "
2229 "EXISTS (SELECT 1 FROM pg_catalog.pg_constraint "
2230 "WHERE conrelid = i.indrelid AND "
2231 "conindid = i.indexrelid AND "
2232 "contype IN ('p','u','x') AND "
2233 "condeferred) AS condeferred,\n");
2246 "pg_catalog.pg_get_expr(i.indpred, i.indrelid, true)\n"
2247 "FROM pg_catalog.pg_index i, pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_am a\n"
2248 "WHERE i.indexrelid = c.oid AND c.oid = '%s' AND c.relam = a.oid\n"
2249 "AND i.indrelid = c2.oid;",
2262 char *indisunique =
PQgetvalue(result, 0, 0);
2263 char *indisprimary =
PQgetvalue(result, 0, 1);
2264 char *indisclustered =
PQgetvalue(result, 0, 2);
2268 char *indisreplident =
PQgetvalue(result, 0, 6);
2269 char *indnullsnotdistinct =
PQgetvalue(result, 0, 7);
2274 if (strcmp(indisprimary,
"t") == 0)
2276 else if (strcmp(indisunique,
"t") == 0)
2279 if (strcmp(indnullsnotdistinct,
"t") == 0)
2289 schemaname, indtable);
2291 if (strlen(indpred))
2294 if (strcmp(indisclustered,
"t") == 0)
2297 if (strcmp(indisvalid,
"t") != 0)
2300 if (strcmp(deferrable,
"t") == 0)
2303 if (strcmp(deferred,
"t") == 0)
2306 if (strcmp(indisreplident,
"t") == 0)
2314 if (tableinfo.relkind == RELKIND_INDEX)
2316 tableinfo.tablespace,
true);
2322 else if (tableinfo.relkind == RELKIND_RELATION ||
2323 tableinfo.relkind == RELKIND_MATVIEW ||
2324 tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
2325 tableinfo.relkind == RELKIND_PARTITIONED_TABLE ||
2326 tableinfo.relkind == RELKIND_PARTITIONED_INDEX ||
2327 tableinfo.relkind == RELKIND_TOASTVALUE)
2334 if (tableinfo.hasindex)
2337 "SELECT c2.relname, i.indisprimary, i.indisunique, "
2338 "i.indisclustered, i.indisvalid, "
2339 "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n "
2340 "pg_catalog.pg_get_constraintdef(con.oid, true), "
2341 "contype, condeferrable, condeferred");
2348 "\nFROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i\n"
2349 " LEFT JOIN pg_catalog.pg_constraint con ON (conrelid = i.indrelid AND conindid = i.indexrelid AND contype IN ('p','u','x'))\n"
2350 "WHERE c.oid = '%s' AND c.oid = i.indrelid AND i.indexrelid = c2.oid\n"
2351 "ORDER BY i.indisprimary DESC, c2.relname;",
2362 for (
i = 0;
i < tuples;
i++)
2376 const char *indexdef;
2377 const char *usingpos;
2382 else if (strcmp(
PQgetvalue(result,
i, 2),
"t") == 0)
2392 usingpos = strstr(indexdef,
" USING ");
2394 indexdef = usingpos + 7;
2427 if (tableinfo.checks)
2430 "SELECT r.conname, "
2431 "pg_catalog.pg_get_constraintdef(r.oid, true)\n"
2432 "FROM pg_catalog.pg_constraint r\n"
2433 "WHERE r.conrelid = '%s' AND r.contype = 'c'\n"
2445 for (
i = 0;
i < tuples;
i++)
2463 if (tableinfo.hastriggers ||
2464 tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
2467 (tableinfo.ispartition || tableinfo.relkind == RELKIND_PARTITIONED_TABLE))
2474 "SELECT conrelid = '%s'::pg_catalog.regclass AS sametable,\n"
2476 " pg_catalog.pg_get_constraintdef(oid, true) AS condef,\n"
2477 " conrelid::pg_catalog.regclass AS ontable\n"
2478 " FROM pg_catalog.pg_constraint,\n"
2479 " pg_catalog.pg_partition_ancestors('%s')\n"
2480 " WHERE conrelid = relid AND contype = 'f' AND conparentid = 0\n"
2481 "ORDER BY sametable DESC, conname;",
2487 "SELECT true as sametable, conname,\n"
2488 " pg_catalog.pg_get_constraintdef(r.oid, true) as condef,\n"
2489 " conrelid::pg_catalog.regclass AS ontable\n"
2490 "FROM pg_catalog.pg_constraint r\n"
2491 "WHERE r.conrelid = '%s' AND r.contype = 'f'\n",
2507 int i_sametable =
PQfnumber(result,
"sametable"),
2508 i_conname =
PQfnumber(result,
"conname"),
2510 i_ontable =
PQfnumber(result,
"ontable");
2513 for (
i = 0;
i < tuples;
i++)
2520 if (strcmp(
PQgetvalue(result,
i, i_sametable),
"f") == 0)
2537 if (tableinfo.hastriggers ||
2538 tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
2543 "SELECT conname, conrelid::pg_catalog.regclass AS ontable,\n"
2544 " pg_catalog.pg_get_constraintdef(oid, true) AS condef\n"
2545 " FROM pg_catalog.pg_constraint c\n"
2546 " WHERE confrelid IN (SELECT pg_catalog.pg_partition_ancestors('%s')\n"
2547 " UNION ALL VALUES ('%s'::pg_catalog.regclass))\n"
2548 " AND contype = 'f' AND conparentid = 0\n"
2549 "ORDER BY conname;",
2555 "SELECT conname, conrelid::pg_catalog.regclass AS ontable,\n"
2556 " pg_catalog.pg_get_constraintdef(oid, true) AS condef\n"
2557 " FROM pg_catalog.pg_constraint\n"
2558 " WHERE confrelid = %s AND contype = 'f'\n"
2559 "ORDER BY conname;",
2571 int i_conname =
PQfnumber(result,
"conname"),
2572 i_ontable =
PQfnumber(result,
"ontable"),
2576 for (
i = 0;
i < tuples;
i++)
2595 " pol.polpermissive,\n");
2598 " 't' as polpermissive,\n");
2600 " 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"
2601 " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n"
2602 " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n"
2603 " CASE pol.polcmd\n"
2604 " WHEN 'r' THEN 'SELECT'\n"
2605 " WHEN 'a' THEN 'INSERT'\n"
2606 " WHEN 'w' THEN 'UPDATE'\n"
2607 " WHEN 'd' THEN 'DELETE'\n"
2609 "FROM pg_catalog.pg_policy pol\n"
2610 "WHERE pol.polrelid = '%s' ORDER BY 1;",
2624 if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0)
2627 if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0)
2630 if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0)
2633 if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0)
2636 if (!tableinfo.rowsecurity && tuples > 0)
2640 for (
i = 0;
i < tuples;
i++)
2676 "stxrelid::pg_catalog.regclass, "
2677 "stxnamespace::pg_catalog.regnamespace::pg_catalog.text AS nsp, "
2679 "pg_catalog.pg_get_statisticsobjdef_columns(oid) AS columns,\n"
2680 " 'd' = any(stxkind) AS ndist_enabled,\n"
2681 " 'f' = any(stxkind) AS deps_enabled,\n"
2682 " 'm' = any(stxkind) AS mcv_enabled,\n"
2684 "FROM pg_catalog.pg_statistic_ext\n"
2685 "WHERE stxrelid = '%s'\n"
2686 "ORDER BY nsp, stxname;",
2699 for (
i = 0;
i < tuples;
i++)
2701 bool gotone =
false;
2703 bool has_dependencies;
2708 has_ndistinct = (strcmp(
PQgetvalue(result,
i, 5),
"t") == 0);
2709 has_dependencies = (strcmp(
PQgetvalue(result,
i, 6),
"t") == 0);
2710 has_mcv = (strcmp(
PQgetvalue(result,
i, 7),
"t") == 0);
2727 has_all = (has_ndistinct && has_dependencies && has_mcv);
2728 has_some = (has_ndistinct || has_dependencies || has_mcv);
2730 if (has_some && !has_all)
2741 if (has_dependencies)
2773 "stxrelid::pg_catalog.regclass, "
2774 "stxnamespace::pg_catalog.regnamespace AS nsp, "
2776 " (SELECT pg_catalog.string_agg(pg_catalog.quote_ident(attname),', ')\n"
2777 " FROM pg_catalog.unnest(stxkeys) s(attnum)\n"
2778 " JOIN pg_catalog.pg_attribute a ON (stxrelid = a.attrelid AND\n"
2779 " a.attnum = s.attnum AND NOT attisdropped)) AS columns,\n"
2780 " 'd' = any(stxkind) AS ndist_enabled,\n"
2781 " 'f' = any(stxkind) AS deps_enabled,\n"
2782 " 'm' = any(stxkind) AS mcv_enabled,\n");
2789 "WHERE stxrelid = '%s'\n"
2803 for (
i = 0;
i < tuples;
i++)
2805 bool gotone =
false;
2848 if (tableinfo.hasrules && tableinfo.relkind != RELKIND_MATVIEW)
2851 "SELECT r.rulename, trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true)), "
2853 "FROM pg_catalog.pg_rewrite r\n"
2854 "WHERE r.ev_class = '%s' ORDER BY 1;",
2867 for (category = 0; category < 4; category++)
2869 have_heading =
false;
2871 for (
i = 0;
i < tuples;
i++)
2873 const char *ruledef;
2874 bool list_rule =
false;
2916 have_heading =
true;
2939 "FROM pg_catalog.pg_publication p\n"
2940 " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n"
2941 " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n"
2942 "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n"
2945 " , pg_get_expr(pr.prqual, c.oid)\n"
2946 " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n"
2947 " (SELECT string_agg(attname, ', ')\n"
2948 " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n"
2949 " pg_catalog.pg_attribute\n"
2950 " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n"
2952 "FROM pg_catalog.pg_publication p\n"
2953 " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n"
2954 " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n"
2955 "WHERE pr.prrelid = '%s'\n"
2960 "FROM pg_catalog.pg_publication p\n"
2961 "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n"
2963 oid, oid, oid, oid);
2971 "FROM pg_catalog.pg_publication p\n"
2972 "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n"
2973 "WHERE pr.prrelid = '%s'\n"
2978 "FROM pg_catalog.pg_publication p\n"
2979 "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n"
2994 for (
i = 0;
i < tuples;
i++)
3016 if ((tableinfo.relkind == RELKIND_VIEW ||
3017 tableinfo.relkind == RELKIND_MATVIEW) &&
verbose)
3022 "SELECT pg_catalog.pg_get_viewdef('%s'::pg_catalog.oid, true);",
3043 if (tableinfo.hasrules)
3046 "SELECT r.rulename, trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true))\n"
3047 "FROM pg_catalog.pg_rewrite r\n"
3048 "WHERE r.ev_class = '%s' AND r.rulename != '_RETURN' ORDER BY 1;",
3059 const char *ruledef;
3077 if (tableinfo.hastriggers)
3084 "pg_catalog.pg_get_triggerdef(t.oid, true), "
3085 "t.tgenabled, t.tgisinternal,\n");
3103 " CASE WHEN t.tgparentid != 0 THEN\n"
3104 " (SELECT u.tgrelid::pg_catalog.regclass\n"
3105 " FROM pg_catalog.pg_trigger AS u,\n"
3106 " pg_catalog.pg_partition_ancestors(t.tgrelid) WITH ORDINALITY AS a(relid, depth)\n"
3107 " WHERE u.tgname = t.tgname AND u.tgrelid = a.relid\n"
3108 " AND u.tgparentid = 0\n"
3109 " ORDER BY a.depth LIMIT 1)\n"
3110 " END AS parent\n");
3115 "FROM pg_catalog.pg_trigger t\n"
3116 "WHERE t.tgrelid = '%s' AND ",
3128 " OR EXISTS (SELECT 1 FROM pg_catalog.pg_depend WHERE objid = t.oid \n"
3129 " AND refclassid = 'pg_catalog.pg_trigger'::pg_catalog.regclass))");
3151 for (category = 0; category <= 4; category++)
3153 have_heading =
false;
3154 for (
i = 0;
i < tuples;
i++)
3158 const char *usingpos;
3159 const char *tgenabled;
3160 const char *tgisinternal;
3167 list_trigger =
false;
3171 if (*tgenabled ==
'O' || *tgenabled ==
't')
3172 list_trigger =
true;
3175 if ((*tgenabled ==
'D' || *tgenabled ==
'f') &&
3176 *tgisinternal ==
'f')
3177 list_trigger =
true;
3180 if ((*tgenabled ==
'D' || *tgenabled ==
'f') &&
3181 *tgisinternal ==
't')
3182 list_trigger =
true;
3185 if (*tgenabled ==
'A')
3186 list_trigger =
true;
3189 if (*tgenabled ==
'R')
3190 list_trigger =
true;
3193 if (list_trigger ==
false)
3197 if (have_heading ==
false)
3218 have_heading =
true;
3223 usingpos = strstr(tgdef,
" TRIGGER ");
3225 tgdef = usingpos + 9;
3244 if (tableinfo.relkind == RELKIND_RELATION ||
3245 tableinfo.relkind == RELKIND_MATVIEW ||
3246 tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
3247 tableinfo.relkind == RELKIND_PARTITIONED_TABLE ||
3248 tableinfo.relkind == RELKIND_PARTITIONED_INDEX ||
3249 tableinfo.relkind == RELKIND_TOASTVALUE)
3251 bool is_partitioned;
3256 is_partitioned = (tableinfo.relkind == RELKIND_PARTITIONED_TABLE ||
3257 tableinfo.relkind == RELKIND_PARTITIONED_INDEX);
3260 if (tableinfo.relkind == RELKIND_FOREIGN_TABLE)
3266 "SELECT s.srvname,\n"
3267 " pg_catalog.array_to_string(ARRAY(\n"
3268 " SELECT pg_catalog.quote_ident(option_name)"
3269 " || ' ' || pg_catalog.quote_literal(option_value)\n"
3270 " FROM pg_catalog.pg_options_to_table(ftoptions)), ', ')\n"
3271 "FROM pg_catalog.pg_foreign_table f,\n"
3272 " pg_catalog.pg_foreign_server s\n"
3273 "WHERE f.ftrelid = '%s' AND s.oid = f.ftserver;",
3291 if (ftoptions && ftoptions[0] !=
'\0')
3301 "SELECT c.oid::pg_catalog.regclass\n"
3302 "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n"
3303 "WHERE c.oid = i.inhparent AND i.inhrelid = '%s'\n"
3304 " AND c.relkind != " CppAsString2(RELKIND_PARTITIONED_TABLE)
3305 " AND c.relkind != " CppAsString2(RELKIND_PARTITIONED_INDEX)
3306 "\nORDER BY inhseqno;",
3314 const char *s =
_(
"Inherits");
3319 for (
i = 0;
i < tuples;
i++)
3339 "SELECT c.oid::pg_catalog.regclass, c.relkind,"
3340 " inhdetachpending,"
3341 " pg_catalog.pg_get_expr(c.relpartbound, c.oid)\n"
3342 "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n"
3343 "WHERE c.oid = i.inhrelid AND i.inhparent = '%s'\n"
3344 "ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT',"
3345 " c.oid::pg_catalog.regclass::pg_catalog.text;",
3349 "SELECT c.oid::pg_catalog.regclass, c.relkind,"
3350 " false AS inhdetachpending,"
3351 " pg_catalog.pg_get_expr(c.relpartbound, c.oid)\n"
3352 "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n"
3353 "WHERE c.oid = i.inhrelid AND i.inhparent = '%s'\n"
3354 "ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT',"
3355 " c.oid::pg_catalog.regclass::pg_catalog.text;",
3359 "SELECT c.oid::pg_catalog.regclass, c.relkind,"
3360 " false AS inhdetachpending, NULL\n"
3361 "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n"
3362 "WHERE c.oid = i.inhrelid AND i.inhparent = '%s'\n"
3363 "ORDER BY c.oid::pg_catalog.regclass::pg_catalog.text;",
3377 if (is_partitioned && tuples == 0)
3397 const char *ct = is_partitioned ?
_(
"Partitions") :
_(
"Child tables");
3400 for (
i = 0;
i < tuples;
i++)
3412 if (child_relkind == RELKIND_PARTITIONED_TABLE ||
3413 child_relkind == RELKIND_PARTITIONED_INDEX)
3426 if (tableinfo.reloftype)
3433 (tableinfo.relkind == RELKIND_RELATION ||
3434 tableinfo.relkind == RELKIND_MATVIEW) &&
3440 tableinfo.relreplident !=
'i' &&
3441 ((strcmp(schemaname,
"pg_catalog") != 0 && tableinfo.relreplident !=
'd') ||
3442 (strcmp(schemaname,
"pg_catalog") == 0 && tableinfo.relreplident !=
'n')))
3444 const char *s =
_(
"Replica Identity");
3448 tableinfo.relreplident ==
'f' ?
"FULL" :
3449 tableinfo.relreplident ==
'n' ?
"NOTHING" :
3456 if (
verbose && tableinfo.relkind != RELKIND_MATVIEW && tableinfo.hasoids)
3473 tableinfo.reloptions && tableinfo.reloptions[0] !=
'\0')
3475 const char *t =
_(
"Options");
3488 if (printTableInitialized)
3513 if (relkind == RELKIND_RELATION ||
3514 relkind == RELKIND_MATVIEW ||
3515 relkind == RELKIND_INDEX ||
3516 relkind == RELKIND_PARTITIONED_TABLE ||
3517 relkind == RELKIND_PARTITIONED_INDEX ||
3518 relkind == RELKIND_TOASTVALUE)
3531 "SELECT spcname FROM pg_catalog.pg_tablespace\n"
3584 const char align =
'l';
3592 "SELECT r.rolname, r.rolsuper, r.rolinherit,\n"
3593 " r.rolcreaterole, r.rolcreatedb, r.rolcanlogin,\n"
3594 " r.rolconnlimit, r.rolvaliduntil,\n"
3595 " ARRAY(SELECT b.rolname\n"
3596 " FROM pg_catalog.pg_auth_members m\n"
3597 " JOIN pg_catalog.pg_roles b ON (m.roleid = b.oid)\n"
3598 " WHERE m.member = r.oid) as memberof");
3614 if (!showSystem && !pattern)
3618 NULL,
"r.rolname", NULL, NULL,
3629 attr =
pg_malloc0((nrows + 1) *
sizeof(*attr));
3641 for (
i = 0;
i < nrows;
i++)
3705 for (
i = 0;
i < nrows;
i++)
3736 "pg_catalog.array_to_string(setconfig, E'\\n') AS \"%s\"\n"
3737 "FROM pg_catalog.pg_db_role_setting s\n"
3738 "LEFT JOIN pg_catalog.pg_database d ON d.oid = setdatabase\n"
3739 "LEFT JOIN pg_catalog.pg_roles r ON r.oid = setrole\n",
3744 NULL,
"r.rolname", NULL, NULL, &havewhere, 1))
3747 NULL,
"d.datname", NULL, NULL,
3765 if (pattern && pattern2)
3766 pg_log_error(
"Did not find any settings for role \"%s\" and database \"%s\".",
3769 pg_log_error(
"Did not find any settings for role \"%s\".",
3777 myopt.
title =
_(
"List of settings");
3805 bool showTables = strchr(tabtypes,
't') != NULL;
3806 bool showIndexes = strchr(tabtypes,
'i') != NULL;
3807 bool showViews = strchr(tabtypes,
'v') != NULL;
3808 bool showMatViews = strchr(tabtypes,
'm') != NULL;
3809 bool showSeq = strchr(tabtypes,
's') != NULL;
3810 bool showForeign = strchr(tabtypes,
'E') != NULL;
3816 bool translate_columns[] = {
false,
false,
true,
false,
false,
false,
false,
false,
false};
3819 if (!(showTables || showIndexes || showViews || showMatViews || showSeq || showForeign))
3820 showTables = showViews = showMatViews = showSeq = showForeign =
true;
3825 "SELECT n.nspname as \"%s\",\n"
3826 " c.relname as \"%s\",\n"
3834 " WHEN " CppAsString2(RELKIND_FOREIGN_TABLE)
" THEN '%s'"
3835 " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE)
" THEN '%s'"
3836 " WHEN " CppAsString2(RELKIND_PARTITIONED_INDEX)
" THEN '%s'"
3838 " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
3857 ",\n c2.relname as \"%s\"",
3868 ",\n CASE c.relpersistence WHEN 'p' THEN '%s' WHEN 't' THEN '%s' WHEN 'u' THEN '%s' END as \"%s\"",
3873 translate_columns[cols_so_far] =
true;
3885 (showTables || showMatViews || showIndexes))
3887 ",\n am.amname as \"%s\"",
3891 ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_table_size(c.oid)) as \"%s\""
3892 ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
3898 "\nFROM pg_catalog.pg_class c"
3899 "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
3902 (showTables || showMatViews || showIndexes))
3904 "\n LEFT JOIN pg_catalog.pg_am am ON am.oid = c.relam");
3908 "\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
3909 "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
3917 if (showSystem || pattern)
3929 if (showSystem || pattern)
3937 if (!showSystem && !pattern)
3939 " AND n.nspname !~ '^pg_toast'\n"
3940 " AND n.nspname <> 'information_schema'\n");
3943 "n.nspname",
"c.relname", NULL,
3944 "pg_catalog.pg_table_is_visible(c.oid)",
3963 pg_log_error(
"Did not find any relation named \"%s\".",
3971 myopt.
title =
_(
"List of relations");
4001 bool showTables = strchr(reltypes,
't') != NULL;
4002 bool showIndexes = strchr(reltypes,
'i') != NULL;
4003 bool showNested = strchr(reltypes,
'n') != NULL;
4008 bool translate_columns[] = {
false,
false,
false,
false,
false,
false,
false,
false,
false};
4009 const char *tabletitle;
4010 bool mixed_output =
false;
4019 pg_log_error(
"The server (version %s) does not support declarative table partitioning.",
4021 sverbuf,
sizeof(sverbuf)));
4026 if (!showTables && !showIndexes)
4027 showTables = showIndexes =
true;
4029 if (showIndexes && !showTables)
4030 tabletitle =
_(
"List of partitioned indexes");
4031 else if (showTables && !showIndexes)
4032 tabletitle =
_(
"List of partitioned tables");
4036 tabletitle =
_(
"List of partitioned relations");
4037 mixed_output =
true;
4043 "SELECT n.nspname as \"%s\",\n"
4044 " c.relname as \"%s\",\n"
4045 " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
4053 ",\n CASE c.relkind"
4054 " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE)
" THEN '%s'"
4055 " WHEN " CppAsString2(RELKIND_PARTITIONED_INDEX)
" THEN '%s'"
4061 translate_columns[3] =
true;
4064 if (showNested || pattern)
4066 ",\n inh.inhparent::pg_catalog.regclass as \"%s\"",
4071 ",\n c2.oid::pg_catalog.regclass as \"%s\"",
4079 ",\n s.dps as \"%s\"",
4082 ",\n s.tps as \"%s\"",
4088 ",\n s.tps as \"%s\"",
4092 ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
4097 "\nFROM pg_catalog.pg_class c"
4098 "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
4102 "\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
4103 "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
4105 if (showNested || pattern)
4107 "\n LEFT JOIN pg_catalog.pg_inherits inh ON c.oid = inh.inhrelid");
4114 ",\n LATERAL (WITH RECURSIVE d\n"
4115 " AS (SELECT inhrelid AS oid, 1 AS level\n"
4116 " FROM pg_catalog.pg_inherits\n"
4117 " WHERE inhparent = c.oid\n"
4119 " SELECT inhrelid, level + 1\n"
4120 " FROM pg_catalog.pg_inherits i\n"
4121 " JOIN d ON i.inhparent = d.oid)\n"
4122 " SELECT pg_catalog.pg_size_pretty(sum(pg_catalog.pg_table_size("
4123 "d.oid))) AS tps,\n"
4124 " pg_catalog.pg_size_pretty(sum("
4125 "\n CASE WHEN d.level = 1"
4126 " THEN pg_catalog.pg_table_size(d.oid) ELSE 0 END)) AS dps\n"
4133 ",\n LATERAL (SELECT pg_catalog.pg_size_pretty(sum("
4134 "\n CASE WHEN ppt.isleaf AND ppt.level = 1"
4135 "\n THEN pg_catalog.pg_table_size(ppt.relid)"
4136 " ELSE 0 END)) AS dps"
4137 ",\n pg_catalog.pg_size_pretty(sum("
4138 "pg_catalog.pg_table_size(ppt.relid))) AS tps"
4139 "\n FROM pg_catalog.pg_partition_tree(c.oid) ppt) s");
4152 " AND NOT c.relispartition\n" :
"");
4156 " AND n.nspname !~ '^pg_toast'\n"
4157 " AND n.nspname <> 'information_schema'\n");
4160 "n.nspname",
"c.relname", NULL,
4161 "pg_catalog.pg_table_is_visible(c.oid)",
4166 mixed_output ?
"\"Type\" DESC, " :
"",
4167 showNested || pattern ?
"\"Parent name\" NULLS FIRST, " :
"");
4206 "SELECT l.lanname AS \"%s\",\n"
4207 " pg_catalog.pg_get_userbyid(l.lanowner) as \"%s\",\n"
4208 " l.lanpltrusted AS \"%s\"",
4216 ",\n NOT l.lanispl AS \"%s\",\n"
4217 " l.lanplcallfoid::pg_catalog.regprocedure AS \"%s\",\n"
4218 " l.lanvalidator::pg_catalog.regprocedure AS \"%s\",\n "
4219 "l.laninline::pg_catalog.regprocedure AS \"%s\",\n ",
4228 ",\n d.description AS \"%s\""
4229 "\nFROM pg_catalog.pg_language l\n"
4230 "LEFT JOIN pg_catalog.pg_description d\n"
4231 " ON d.classoid = l.tableoid AND d.objoid = l.oid\n"
4232 " AND d.objsubid = 0\n",
4237 NULL,
"l.lanname", NULL, NULL,
4241 if (!showSystem && !pattern)
4253 myopt.
title =
_(
"List of languages");
4278 "SELECT n.nspname as \"%s\",\n"
4279 " t.typname as \"%s\",\n"
4280 " pg_catalog.format_type(t.typbasetype, t.typtypmod) as \"%s\",\n"
4281 " (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type bt\n"
4282 " WHERE c.oid = t.typcollation AND bt.oid = t.typbasetype AND t.typcollation <> bt.typcollation) as \"%s\",\n"
4283 " CASE WHEN t.typnotnull THEN 'not null' END as \"%s\",\n"
4284 " t.typdefault as \"%s\",\n"
4285 " pg_catalog.array_to_string(ARRAY(\n"
4286 " SELECT pg_catalog.pg_get_constraintdef(r.oid, true) FROM pg_catalog.pg_constraint r WHERE t.oid = r.contypid\n"
4287 " ), ' ') as \"%s\"",
4301 ",\n d.description as \"%s\"",
4306 "\nFROM pg_catalog.pg_type t\n"
4307 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
4311 " LEFT JOIN pg_catalog.pg_description d "
4312 "ON d.classoid = t.tableoid AND d.objoid = t.oid "
4313 "AND d.objsubid = 0\n");
4317 if (!showSystem && !pattern)
4319 " AND n.nspname <> 'information_schema'\n");
4322 "n.nspname",
"t.typname", NULL,
4323 "pg_catalog.pg_type_is_visible(t.oid)",
4335 myopt.
title =
_(
"List of domains");
4355 static const bool translate_columns[] =
4356 {
false,
false,
false,
false,
true,
false};
4361 "SELECT n.nspname AS \"%s\",\n"
4362 " c.conname AS \"%s\",\n"
4363 " pg_catalog.pg_encoding_to_char(c.conforencoding) AS \"%s\",\n"
4364 " pg_catalog.pg_encoding_to_char(c.contoencoding) AS \"%s\",\n"
4365 " CASE WHEN c.condefault THEN '%s'\n"
4366 " ELSE '%s' END AS \"%s\"",
4376 ",\n d.description AS \"%s\"",
4380 "\nFROM pg_catalog.pg_conversion c\n"
4381 " JOIN pg_catalog.pg_namespace n "
4382 "ON n.oid = c.connamespace\n");
4386 "LEFT JOIN pg_catalog.pg_description d "
4387 "ON d.classoid = c.tableoid\n"
4388 " AND d.objoid = c.oid "
4389 "AND d.objsubid = 0\n");
4393 if (!showSystem && !pattern)
4395 " AND n.nspname <> 'information_schema'\n");
4398 "n.nspname",
"c.conname", NULL,
4399 "pg_catalog.pg_conversion_is_visible(c.oid)",
4411 myopt.
title =
_(
"List of conversions");
4437 "SELECT s.name AS \"%s\", "
4438 "pg_catalog.current_setting(s.name) AS \"%s\"",
4445 ", s.vartype AS \"%s\", s.context AS \"%s\", ",
4459 " LEFT JOIN pg_catalog.pg_parameter_acl p\n"
4460 " ON pg_catalog.lower(s.name) = p.parname\n");
4465 NULL,
"pg_catalog.lower(s.name)", NULL,
4469 " s.setting IS DISTINCT FROM s.boot_val\n");
4480 myopt.
title =
_(
"List of configuration parameters");
4482 myopt.
title =
_(
"List of non-default configuration parameters");
4502 static const bool translate_columns[] =
4503 {
false,
false,
false,
true,
false,
false,
false};
4509 pg_log_error(
"The server (version %s) does not support event triggers.",
4511 sverbuf,
sizeof(sverbuf)));
4518 "SELECT evtname as \"%s\", "
4519 "evtevent as \"%s\", "
4520 "pg_catalog.pg_get_userbyid(e.evtowner) as \"%s\",\n"
4521 " case evtenabled when 'O' then '%s'"
4522 " when 'R' then '%s'"
4523 " when 'A' then '%s'"
4524 " when 'D' then '%s' end as \"%s\",\n"
4525 " e.evtfoid::pg_catalog.regproc as \"%s\", "
4526 "pg_catalog.array_to_string(array(select x"
4527 " from pg_catalog.unnest(evttags) as t(x)), ', ') as \"%s\"",
4540 ",\npg_catalog.obj_description(e.oid, 'pg_event_trigger') as \"%s\"",
4543 "\nFROM pg_catalog.pg_event_trigger e ");
4546 NULL,
"evtname", NULL, NULL,
4558 myopt.
title =
_(
"List of event triggers");
4585 pg_log_error(
"The server (version %s) does not support extended statistics.",
4587 sverbuf,
sizeof(sverbuf)));
4594 "es.stxnamespace::pg_catalog.regnamespace::pg_catalog.text AS \"%s\", \n"
4595 "es.stxname AS \"%s\", \n",
4601 "pg_catalog.format('%%s FROM %%s', \n"
4602 " pg_catalog.pg_get_statisticsobjdef_columns(es.oid), \n"
4603 " es.stxrelid::pg_catalog.regclass) AS \"%s\"",
4607 "pg_catalog.format('%%s FROM %%s', \n"
4608 " (SELECT pg_catalog.string_agg(pg_catalog.quote_ident(a.attname),', ') \n"
4609 " FROM pg_catalog.unnest(es.stxkeys) s(attnum) \n"
4610 " JOIN pg_catalog.pg_attribute a \n"
4611 " ON (es.stxrelid = a.attrelid \n"
4612 " AND a.attnum = s.attnum \n"
4613 " AND NOT a.attisdropped)), \n"
4614 "es.stxrelid::pg_catalog.regclass) AS \"%s\"",
4618 ",\nCASE WHEN 'd' = any(es.stxkind) THEN 'defined' \n"
4620 "CASE WHEN 'f' = any(es.stxkind) THEN 'defined' \n"
4631 ",\nCASE WHEN 'm' = any(es.stxkind) THEN 'defined' \n"
4637 " \nFROM pg_catalog.pg_statistic_ext es \n");
4641 "es.stxnamespace::pg_catalog.regnamespace::pg_catalog.text",
"es.stxname",
4642 NULL,
"pg_catalog.pg_statistics_obj_is_visible(es.oid)",
4654 myopt.
title =
_(
"List of extended statistics");
4674 static const bool translate_columns[] = {
false,
false,
false,
true,
false};
4679 "SELECT pg_catalog.format_type(castsource, NULL) AS \"%s\",\n"
4680 " pg_catalog.format_type(casttarget, NULL) AS \"%s\",\n",
4690 " CASE WHEN c.castmethod = '%c' THEN '(binary coercible)'\n"
4691 " WHEN c.castmethod = '%c' THEN '(with inout)'\n"
4693 " END AS \"%s\",\n",
4694 COERCION_METHOD_BINARY,
4695 COERCION_METHOD_INOUT,
4699 " CASE WHEN c.castcontext = '%c' THEN '%s'\n"
4700 " WHEN c.castcontext = '%c' THEN '%s'\n"
4703 COERCION_CODE_EXPLICIT,
4705 COERCION_CODE_ASSIGNMENT,
4712 ",\n d.description AS \"%s\"",
4720 "\nFROM pg_catalog.pg_cast c LEFT JOIN pg_catalog.pg_proc p\n"
4721 " ON c.castfunc = p.oid\n"
4722 " LEFT JOIN pg_catalog.pg_type ts\n"
4723 " ON c.castsource = ts.oid\n"
4724 " LEFT JOIN pg_catalog.pg_namespace ns\n"
4725 " ON ns.oid = ts.typnamespace\n"
4726 " LEFT JOIN pg_catalog.pg_type tt\n"
4727 " ON c.casttarget = tt.oid\n"
4728 " LEFT JOIN pg_catalog.pg_namespace nt\n"
4729 " ON nt.oid = tt.typnamespace\n");
4733 " LEFT JOIN pg_catalog.pg_description d\n"
4734 " ON d.classoid = c.tableoid AND d.objoid = "
4735 "c.oid AND d.objsubid = 0\n");
4744 "ns.nspname",
"ts.typname",
4745 "pg_catalog.format_type(ts.oid, NULL)",
4746 "pg_catalog.pg_type_is_visible(ts.oid)",
4753 "nt.nspname",
"tt.typname",
4754 "pg_catalog.format_type(tt.oid, NULL)",
4755 "pg_catalog.pg_type_is_visible(tt.oid)",
4767 myopt.
title =
_(
"List of casts");
4789 static const bool translate_columns[] = {
false,
false,
false,
false,
false,
false,
true,
false};
4794 "SELECT n.nspname AS \"%s\",\n"
4795 " c.collname AS \"%s\",\n"
4796 " c.collcollate AS \"%s\",\n"
4797 " c.collctype AS \"%s\"",
4805 ",\n c.colliculocale AS \"%s\"",
4809 ",\n c.collcollate AS \"%s\"",
4814 ",\n CASE c.collprovider WHEN 'd' THEN 'default' WHEN 'c' THEN 'libc' WHEN 'i' THEN 'icu' END AS \"%s\"",
4818 ",\n 'libc' AS \"%s\"",
4823 ",\n CASE WHEN c.collisdeterministic THEN '%s' ELSE '%s' END AS \"%s\"",
4828 ",\n '%s' AS \"%s\"",
4834 ",\n pg_catalog.obj_description(c.oid, 'pg_collation') AS \"%s\"",
4838 "\nFROM pg_catalog.pg_collation c, pg_catalog.pg_namespace n\n"
4839 "WHERE n.oid = c.collnamespace\n");
4841 if (!showSystem && !pattern)
4843 " AND n.nspname <> 'information_schema'\n");
4851 appendPQExpBufferStr(&
buf,
" AND c.collencoding IN (-1, pg_catalog.pg_char_to_encoding(pg_catalog.getdatabaseencoding()))\n");
4854 "n.nspname",
"c.collname", NULL,
4855 "pg_catalog.pg_collation_is_visible(c.oid)",
4867 myopt.
title =
_(
"List of collations");
4889 int pub_schema_tuples = 0;
4890 char **footers = NULL;
4894 "SELECT n.nspname AS \"%s\",\n"
4895 " pg_catalog.pg_get_userbyid(n.nspowner) AS \"%s\"",
4904 ",\n pg_catalog.obj_description(n.oid, 'pg_namespace') AS \"%s\"",
4909 "\nFROM pg_catalog.pg_namespace n\n");
4911 if (!showSystem && !pattern)
4913 "WHERE n.nspname !~ '^pg_' AND n.nspname <> 'information_schema'\n");
4916 !showSystem && !pattern,
false,
4917 NULL,
"n.nspname", NULL,
4932 myopt.
title =
_(
"List of schemas");
4942 "FROM pg_catalog.pg_publication p\n"
4943 " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n"
4944 " JOIN pg_catalog.pg_namespace n ON n.oid = pn.pnnspid \n"
4945 "WHERE n.nspname = '%s'\n"
4957 if (pub_schema_tuples > 0)
4964 footers = (
char **)
pg_malloc((1 + pub_schema_tuples + 1) *
sizeof(
char *));
4968 for (
i = 0;
i < pub_schema_tuples;
i++)
4976 footers[
i + 1] = NULL;
4991 char **footer = NULL;
4993 for (footer = footers; *footer; footer++)
5021 " n.nspname as \"%s\",\n"
5022 " p.prsname as \"%s\",\n"
5023 " pg_catalog.obj_description(p.oid, 'pg_ts_parser') as \"%s\"\n"
5024 "FROM pg_catalog.pg_ts_parser p\n"
5025 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.prsnamespace\n",
5032 "n.nspname",
"p.prsname", NULL,
5033 "pg_catalog.pg_ts_parser_is_visible(p.oid)",
5045 myopt.
title =
_(
"List of text search parsers");
5070 "FROM pg_catalog.pg_ts_parser p\n"
5071 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.prsnamespace\n"
5075 "n.nspname",
"p.prsname", NULL,
5076 "pg_catalog.pg_ts_parser_is_visible(p.oid)",
5092 pg_log_error(
"Did not find any text search parser named \"%s\".",
5104 const char *nspname = NULL;
5105 const char *prsname;
5136 static const bool translate_columns[] = {
true,
false,
false};
5141 "SELECT '%s' AS \"%s\",\n"
5142 " p.prsstart::pg_catalog.regproc AS \"%s\",\n"
5143 " pg_catalog.obj_description(p.prsstart, 'pg_proc') as \"%s\"\n"
5144 " FROM pg_catalog.pg_ts_parser p\n"
5145 " WHERE p.oid = '%s'\n"
5148 " p.prstoken::pg_catalog.regproc,\n"
5149 " pg_catalog.obj_description(p.prstoken, 'pg_proc')\n"
5150 " FROM pg_catalog.pg_ts_parser p\n"
5151 " WHERE p.oid = '%s'\n"
5154 " p.prsend::pg_catalog.regproc,\n"
5155 " pg_catalog.obj_description(p.prsend, 'pg_proc')\n"
5156 " FROM pg_catalog.pg_ts_parser p\n"
5157 " WHERE p.oid = '%s'\n"
5160 " p.prsheadline::pg_catalog.regproc,\n"
5161 " pg_catalog.obj_description(p.prsheadline, 'pg_proc')\n"