18#include "catalog/pg_am_d.h"
19#include "catalog/pg_amop_d.h"
20#include "catalog/pg_attribute_d.h"
21#include "catalog/pg_cast_d.h"
22#include "catalog/pg_class_d.h"
23#include "catalog/pg_collation_d.h"
24#include "catalog/pg_constraint_d.h"
25#include "catalog/pg_default_acl_d.h"
26#include "catalog/pg_proc_d.h"
27#include "catalog/pg_publication_d.h"
28#include "catalog/pg_statistic_ext_d.h"
29#include "catalog/pg_subscription_d.h"
30#include "catalog/pg_type_d.h"
41 const char *relationname,
53 const char *pnspname,
const char *prsname);
57 bool have_where,
bool force_escape,
58 const char *schemavar,
const char *namevar,
59 const char *altnamevar,
60 const char *visibilityrule,
61 bool *added_clause,
int maxparts);
87 "SELECT n.nspname as \"%s\",\n"
88 " p.proname AS \"%s\",\n"
89 " pg_catalog.format_type(p.prorettype, NULL) AS \"%s\",\n"
90 " CASE WHEN p.pronargs = 0\n"
91 " THEN CAST('*' AS pg_catalog.text)\n"
92 " ELSE pg_catalog.pg_get_function_arguments(p.oid)\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.prokind = " CppAsString2(PROKIND_AGGREGATE)
"\n",
108 " pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"\n"
109 "FROM pg_catalog.pg_proc p\n"
110 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n"
111 "WHERE p.proisagg\n",
114 if (!showSystem && !pattern)
116 " AND n.nspname <> 'information_schema'\n");
119 "n.nspname",
"p.proname", NULL,
120 "pg_catalog.pg_function_is_visible(p.oid)",
134 myopt.
title =
_(
"List of aggregate functions");
153 static const bool translate_columns[] = {
false,
true,
false,
false};
159 pg_log_error(
"The server (version %s) does not support access methods.",
161 sverbuf,
sizeof(sverbuf)));
168 "SELECT amname AS \"%s\",\n"
181 ",\n amhandler AS \"%s\",\n"
182 " pg_catalog.obj_description(oid, 'pg_am') AS \"%s\"",
188 "\nFROM pg_catalog.pg_am\n");
191 NULL,
"amname", NULL,
206 myopt.
title =
_(
"List of access methods");
231 "SELECT spcname AS \"%s\",\n"
232 " pg_catalog.pg_get_userbyid(spcowner) AS \"%s\",\n"
233 " pg_catalog.pg_tablespace_location(oid) AS \"%s\"",
243 ",\n spcoptions AS \"%s\""
244 ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_tablespace_size(oid)) AS \"%s\""
245 ",\n pg_catalog.shobj_description(oid, 'pg_tablespace') AS \"%s\"",
252 "\nFROM pg_catalog.pg_tablespace\n");
255 NULL,
"spcname", NULL,
270 myopt.
title =
_(
"List of tablespaces");
296 char **arg_patterns,
int num_arg_patterns,
299 bool showAggregate = strchr(functypes,
'a') != NULL;
300 bool showNormal = strchr(functypes,
'n') != NULL;
301 bool showProcedure = strchr(functypes,
'p') != NULL;
302 bool showTrigger = strchr(functypes,
't') != NULL;
303 bool showWindow = strchr(functypes,
'w') != NULL;
308 static const bool translate_columns[] = {
false,
false,
false,
false,
true,
true,
true,
false,
true,
true,
false,
false,
false,
false};
311 static const bool translate_columns_pre_96[] = {
false,
false,
false,
false,
true,
true,
false,
true,
true,
false,
false,
false,
false};
313 if (strlen(functypes) != strspn(functypes,
"anptwSx+"))
323 pg_log_error(
"\\df does not take a \"%c\" option with server version %s",
326 sverbuf,
sizeof(sverbuf)));
330 if (!showAggregate && !showNormal && !showProcedure && !showTrigger && !showWindow)
332 showAggregate = showNormal = showTrigger = showWindow =
true;
334 showProcedure =
true;
340 "SELECT n.nspname as \"%s\",\n"
341 " p.proname as \"%s\",\n",
347 " pg_catalog.pg_get_function_result(p.oid) as \"%s\",\n"
348 " pg_catalog.pg_get_function_arguments(p.oid) as \"%s\",\n"
365 " pg_catalog.pg_get_function_result(p.oid) as \"%s\",\n"
366 " pg_catalog.pg_get_function_arguments(p.oid) as \"%s\",\n"
368 " WHEN p.proisagg THEN '%s'\n"
369 " WHEN p.proiswindow THEN '%s'\n"
370 " WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN '%s'\n"
386 " WHEN p.provolatile = "
388 " WHEN p.provolatile = "
390 " WHEN p.provolatile = "
400 " WHEN p.proparallel = "
402 " WHEN p.proparallel = "
404 " WHEN p.proparallel = "
412 ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\""
413 ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\""
414 ",\n CASE WHEN p.proleakproof THEN '%s' ELSE '%s' END as \"%s\"",
425 ",\n l.lanname as \"%s\"",
428 ",\n CASE WHEN l.lanname IN ('internal', 'c') THEN p.prosrc END as \"%s\"",
431 ",\n pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"",
436 "\nFROM pg_catalog.pg_proc p"
437 "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n");
439 for (
int i = 0;
i < num_arg_patterns;
i++)
442 " LEFT JOIN pg_catalog.pg_type t%d ON t%d.oid = p.proargtypes[%d]\n"
443 " LEFT JOIN pg_catalog.pg_namespace nt%d ON nt%d.oid = t%d.typnamespace\n",
449 " LEFT JOIN pg_catalog.pg_language l ON l.oid = p.prolang\n");
454 if (showNormal && showAggregate && showProcedure && showTrigger && showWindow)
514 bool needs_or =
false;
533 "p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype\n");
558 "n.nspname",
"p.proname", NULL,
559 "pg_catalog.pg_function_is_visible(p.oid)",
563 for (
int i = 0;
i < num_arg_patterns;
i++)
565 if (strcmp(arg_patterns[
i],
"-") != 0)
577 snprintf(nspname,
sizeof(nspname),
"nt%d.nspname",
i);
580 "pg_catalog.format_type(t%d.oid, NULL)",
i);
582 "pg_catalog.pg_type_is_visible(t%d.oid)",
i);
597 if (!showSystem && !func_pattern)
599 " AND n.nspname <> 'information_schema'\n");
608 myopt.
title =
_(
"List of functions");
647 "SELECT n.nspname as \"%s\",\n"
648 " pg_catalog.format_type(t.oid, NULL) AS \"%s\",\n",
654 " t.typname AS \"%s\",\n"
655 " CASE WHEN t.typrelid != 0\n"
656 " THEN CAST('tuple' AS pg_catalog.text)\n"
657 " WHEN t.typlen < 0\n"
658 " THEN CAST('var' AS pg_catalog.text)\n"
659 " ELSE CAST(t.typlen AS pg_catalog.text)\n"
661 " pg_catalog.array_to_string(\n"
663 " SELECT e.enumlabel\n"
664 " FROM pg_catalog.pg_enum e\n"
665 " WHERE e.enumtypid = t.oid\n"
666 " ORDER BY e.enumsortorder\n"
670 " pg_catalog.pg_get_userbyid(t.typowner) AS \"%s\",\n",
680 " pg_catalog.obj_description(t.oid, 'pg_type') as \"%s\"\n",
684 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
692 " FROM pg_catalog.pg_class c "
693 "WHERE c.oid = t.typrelid))\n");
698 if (pattern == NULL || strstr(pattern,
"[]") == NULL)
699 appendPQExpBufferStr(&
buf,
" AND NOT EXISTS(SELECT 1 FROM pg_catalog.pg_type el WHERE el.oid = t.typelem AND el.typarray = t.oid)\n");
701 if (!showSystem && !pattern)
703 " AND n.nspname <> 'information_schema'\n");
708 "n.nspname",
"t.typname",
709 "pg_catalog.format_type(t.oid, NULL)",
710 "pg_catalog.pg_type_is_visible(t.oid)",
724 myopt.
title =
_(
"List of data types");
745 static const char *
const typename_map[] = {
751 "decimal",
"numeric",
752 "float",
"double precision",
759 "bool[]",
"boolean[]",
760 "decimal[]",
"numeric[]",
761 "float[]",
"double precision[]",
762 "float4[]",
"real[]",
763 "float8[]",
"double precision[]",
764 "int[]",
"integer[]",
765 "int2[]",
"smallint[]",
766 "int4[]",
"integer[]",
767 "int8[]",
"bigint[]",
768 "time[]",
"time without time zone[]",
769 "timetz[]",
"time with time zone[]",
770 "timestamp[]",
"timestamp without time zone[]",
771 "timestamptz[]",
"timestamp with time zone[]",
772 "varbit[]",
"bit varying[]",
773 "varchar[]",
"character varying[]",
779 for (
int i = 0; typename_map[
i] != NULL;
i += 2)
782 return typename_map[
i + 1];
794 char **arg_patterns,
int num_arg_patterns,
800 static const bool translate_columns[] = {
false,
false,
false,
false,
false,
false,
true,
false};
821 "SELECT n.nspname as \"%s\",\n"
822 " o.oprname AS \"%s\",\n"
823 " CASE WHEN o.oprkind='l' THEN NULL ELSE pg_catalog.format_type(o.oprleft, NULL) END AS \"%s\",\n"
824 " CASE WHEN o.oprkind='r' THEN NULL ELSE pg_catalog.format_type(o.oprright, NULL) END AS \"%s\",\n"
825 " pg_catalog.format_type(o.oprresult, NULL) AS \"%s\",\n",
834 " o.oprcode AS \"%s\",\n"
835 " CASE WHEN p.proleakproof THEN '%s' ELSE '%s' END AS \"%s\",\n",
842 " coalesce(pg_catalog.obj_description(o.oid, 'pg_operator'),\n"
843 " pg_catalog.obj_description(o.oprcode, 'pg_proc')) AS \"%s\"\n"
844 "FROM pg_catalog.pg_operator o\n"
845 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = o.oprnamespace\n",
848 if (num_arg_patterns >= 2)
850 num_arg_patterns = 2;
852 " LEFT JOIN pg_catalog.pg_type t0 ON t0.oid = o.oprleft\n"
853 " LEFT JOIN pg_catalog.pg_namespace nt0 ON nt0.oid = t0.typnamespace\n"
854 " LEFT JOIN pg_catalog.pg_type t1 ON t1.oid = o.oprright\n"
855 " LEFT JOIN pg_catalog.pg_namespace nt1 ON nt1.oid = t1.typnamespace\n");
857 else if (num_arg_patterns == 1)
860 " LEFT JOIN pg_catalog.pg_type t0 ON t0.oid = o.oprright\n"
861 " LEFT JOIN pg_catalog.pg_namespace nt0 ON nt0.oid = t0.typnamespace\n");
866 " LEFT JOIN pg_catalog.pg_proc p ON p.oid = o.oprcode\n");
868 if (!showSystem && !oper_pattern)
870 " AND n.nspname <> 'information_schema'\n");
873 !showSystem && !oper_pattern,
true,
874 "n.nspname",
"o.oprname", NULL,
875 "pg_catalog.pg_operator_is_visible(o.oid)",
879 if (num_arg_patterns == 1)
882 for (
int i = 0;
i < num_arg_patterns;
i++)
884 if (strcmp(arg_patterns[
i],
"-") != 0)
896 snprintf(nspname,
sizeof(nspname),
"nt%d.nspname",
i);
899 "pg_catalog.format_type(t%d.oid, NULL)",
i);
901 "pg_catalog.pg_type_is_visible(t%d.oid)",
i);
923 myopt.
title =
_(
"List of operators");
955 " d.datname as \"%s\",\n"
956 " pg_catalog.pg_get_userbyid(d.datdba) as \"%s\",\n"
957 " pg_catalog.pg_encoding_to_char(d.encoding) as \"%s\",\n",
963 " CASE d.datlocprovider "
964 "WHEN " CppAsString2(COLLPROVIDER_BUILTIN)
" THEN 'builtin' "
971 " 'libc' AS \"%s\",\n",
974 " d.datcollate as \"%s\",\n"
975 " d.datctype as \"%s\",\n",
980 " d.datlocale as \"%s\",\n",
984 " d.daticulocale as \"%s\",\n",
988 " NULL as \"%s\",\n",
992 " d.daticurules as \"%s\",\n",
996 " NULL as \"%s\",\n",
1002 ",\n CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT')\n"
1003 " THEN pg_catalog.pg_size_pretty(pg_catalog.pg_database_size(d.datname))\n"
1004 " ELSE 'No Access'\n"
1006 ",\n t.spcname as \"%s\""
1007 ",\n pg_catalog.shobj_description(d.oid, 'pg_database') as \"%s\"",
1012 "\nFROM pg_catalog.pg_database d\n");
1015 " JOIN pg_catalog.pg_tablespace t on d.dattablespace = t.oid\n");
1020 NULL,
"d.datname", NULL, NULL,
1034 myopt.
title =
_(
"List of databases");
1054 static const bool translate_columns[] = {
false,
false,
true,
false,
false,
false};
1062 "SELECT n.nspname as \"%s\",\n"
1063 " c.relname as \"%s\",\n"
1069 " WHEN " CppAsString2(RELKIND_FOREIGN_TABLE)
" THEN '%s'"
1070 " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE)
" THEN '%s'"
1091 ",\n pg_catalog.array_to_string(ARRAY(\n"
1092 " SELECT attname || E':\\n ' || pg_catalog.array_to_string(attacl, E'\\n ')\n"
1093 " FROM pg_catalog.pg_attribute a\n"
1094 " WHERE attrelid = c.oid AND NOT attisdropped AND attacl IS NOT NULL\n"
1095 " ), E'\\n') AS \"%s\"",
1100 ",\n pg_catalog.array_to_string(ARRAY(\n"
1102 " || CASE WHEN polcmd != '*' THEN\n"
1103 " E' (' || polcmd::pg_catalog.text || E'):'\n"
1106 " || CASE WHEN polqual IS NOT NULL THEN\n"
1107 " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n"
1110 " || CASE WHEN polwithcheck IS NOT NULL THEN\n"
1111 " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n"
1114 " || CASE WHEN polroles <> '{0}' THEN\n"
1115 " E'\\n to: ' || pg_catalog.array_to_string(\n"
1118 " FROM pg_catalog.pg_roles\n"
1119 " WHERE oid = ANY (polroles)\n"
1124 " FROM pg_catalog.pg_policy pol\n"
1125 " WHERE polrelid = c.oid), E'\\n')\n"
1131 ",\n pg_catalog.array_to_string(ARRAY(\n"
1133 " || CASE WHEN NOT polpermissive THEN\n"
1134 " E' (RESTRICTIVE)'\n"
1136 " || CASE WHEN polcmd != '*' THEN\n"
1137 " E' (' || polcmd::pg_catalog.text || E'):'\n"
1140 " || CASE WHEN polqual IS NOT NULL THEN\n"
1141 " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n"
1144 " || CASE WHEN polwithcheck IS NOT NULL THEN\n"
1145 " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n"
1148 " || CASE WHEN polroles <> '{0}' THEN\n"
1149 " E'\\n to: ' || pg_catalog.array_to_string(\n"
1152 " FROM pg_catalog.pg_roles\n"
1153 " WHERE oid = ANY (polroles)\n"
1158 " FROM pg_catalog.pg_policy pol\n"
1159 " WHERE polrelid = c.oid), E'\\n')\n"
1164 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
1165 "WHERE c.relkind IN ("
1173 if (!showSystem && !pattern)
1175 " AND n.nspname <> 'information_schema'\n");
1178 "n.nspname",
"c.relname", NULL,
1179 "pg_catalog.pg_table_is_visible(c.oid)",
1218 static const bool translate_columns[] = {
false,
false,
true,
false};
1223 "SELECT pg_catalog.pg_get_userbyid(d.defaclrole) AS \"%s\",\n"
1224 " n.nspname AS \"%s\",\n"
1225 " CASE d.defaclobjtype "
1226 " WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' WHEN '%c' THEN '%s'"
1227 " WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' END AS \"%s\",\n"
1239 DEFACLOBJ_NAMESPACE,
1241 DEFACLOBJ_LARGEOBJECT,
1248 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.defaclnamespace\n");
1253 "pg_catalog.pg_get_userbyid(d.defaclrole)",
1299 static const bool translate_columns[] = {
false,
false,
true,
false};
1304 "SELECT DISTINCT tt.nspname AS \"%s\", tt.name AS \"%s\", tt.object AS \"%s\", d.description AS \"%s\"\n"
1313 " SELECT pgc.oid as oid, pgc.tableoid AS tableoid,\n"
1314 " n.nspname as nspname,\n"
1315 " CAST(pgc.conname AS pg_catalog.text) as name,"
1316 " CAST('%s' AS pg_catalog.text) as object\n"
1317 " FROM pg_catalog.pg_constraint pgc\n"
1318 " JOIN pg_catalog.pg_class c "
1319 "ON c.oid = pgc.conrelid\n"
1320 " LEFT JOIN pg_catalog.pg_namespace n "
1321 " ON n.oid = c.relnamespace\n",
1324 if (!showSystem && !pattern)
1326 " AND n.nspname <> 'information_schema'\n");
1329 false,
"n.nspname",
"pgc.conname", NULL,
1330 "pg_catalog.pg_table_is_visible(c.oid)",
1337 " SELECT pgc.oid as oid, pgc.tableoid AS tableoid,\n"
1338 " n.nspname as nspname,\n"
1339 " CAST(pgc.conname AS pg_catalog.text) as name,"
1340 " CAST('%s' AS pg_catalog.text) as object\n"
1341 " FROM pg_catalog.pg_constraint pgc\n"
1342 " JOIN pg_catalog.pg_type t "
1343 "ON t.oid = pgc.contypid\n"
1344 " LEFT JOIN pg_catalog.pg_namespace n "
1345 " ON n.oid = t.typnamespace\n",
1348 if (!showSystem && !pattern)
1350 " AND n.nspname <> 'information_schema'\n");
1353 false,
"n.nspname",
"pgc.conname", NULL,
1354 "pg_catalog.pg_type_is_visible(t.oid)",
1361 " SELECT o.oid as oid, o.tableoid as tableoid,\n"
1362 " n.nspname as nspname,\n"
1363 " CAST(o.opcname AS pg_catalog.text) as name,\n"
1364 " CAST('%s' AS pg_catalog.text) as object\n"
1365 " FROM pg_catalog.pg_opclass o\n"
1366 " JOIN pg_catalog.pg_am am ON "
1367 "o.opcmethod = am.oid\n"
1368 " JOIN pg_catalog.pg_namespace n ON "
1369 "n.oid = o.opcnamespace\n",
1372 if (!showSystem && !pattern)
1374 " AND n.nspname <> 'information_schema'\n");
1377 "n.nspname",
"o.opcname", NULL,
1378 "pg_catalog.pg_opclass_is_visible(o.oid)",
1385 " SELECT opf.oid as oid, opf.tableoid as tableoid,\n"
1386 " n.nspname as nspname,\n"
1387 " CAST(opf.opfname AS pg_catalog.text) AS name,\n"
1388 " CAST('%s' AS pg_catalog.text) as object\n"
1389 " FROM pg_catalog.pg_opfamily opf\n"
1390 " JOIN pg_catalog.pg_am am "
1391 "ON opf.opfmethod = am.oid\n"
1392 " JOIN pg_catalog.pg_namespace n "
1393 "ON opf.opfnamespace = n.oid\n",
1396 if (!showSystem && !pattern)
1398 " AND n.nspname <> 'information_schema'\n");
1401 "n.nspname",
"opf.opfname", NULL,
1402 "pg_catalog.pg_opfamily_is_visible(opf.oid)",
1409 " SELECT r.oid as oid, r.tableoid as tableoid,\n"
1410 " n.nspname as nspname,\n"
1411 " CAST(r.rulename AS pg_catalog.text) as name,"
1412 " CAST('%s' AS pg_catalog.text) as object\n"
1413 " FROM pg_catalog.pg_rewrite r\n"
1414 " JOIN pg_catalog.pg_class c ON c.oid = r.ev_class\n"
1415 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
1416 " WHERE r.rulename != '_RETURN'\n",
1419 if (!showSystem && !pattern)
1421 " AND n.nspname <> 'information_schema'\n");
1424 "n.nspname",
"r.rulename", NULL,
1425 "pg_catalog.pg_table_is_visible(c.oid)",
1432 " SELECT t.oid as oid, t.tableoid as tableoid,\n"
1433 " n.nspname as nspname,\n"
1434 " CAST(t.tgname AS pg_catalog.text) as name,"
1435 " CAST('%s' AS pg_catalog.text) as object\n"
1436 " FROM pg_catalog.pg_trigger t\n"
1437 " JOIN pg_catalog.pg_class c ON c.oid = t.tgrelid\n"
1438 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n",
1441 if (!showSystem && !pattern)
1443 " AND n.nspname <> 'information_schema'\n");
1446 "n.nspname",
"t.tgname", NULL,
1447 "pg_catalog.pg_table_is_visible(c.oid)",
1453 " JOIN pg_catalog.pg_description d ON (tt.oid = d.objoid AND tt.tableoid = d.classoid AND d.objsubid = 0)\n");
1462 myopt.
title =
_(
"Object descriptions");
1499 "FROM pg_catalog.pg_class c\n"
1500 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n");
1502 if (!showSystem && !pattern)
1504 " AND n.nspname <> 'information_schema'\n");
1507 "n.nspname",
"c.relname", NULL,
1508 "pg_catalog.pg_table_is_visible(c.oid)",
1527 pg_log_error(
"Did not find any relation named \"%s\".",
1539 const char *nspname;
1571 const char *relationname,
1575 bool retval =
false;
1580 bool printTableInitialized =
false;
1582 char *view_def = NULL;
1587 int attname_col = -1,
1590 attnotnull_col = -1,
1592 attidentity_col = -1,
1593 attgenerated_col = -1,
1594 isindexkey_col = -1,
1597 attstorage_col = -1,
1598 attcompression_col = -1,
1599 attstattarget_col = -1,
1610 bool forcerowsecurity;
1616 char relpersistence;
1620 bool show_column_details =
false;
1634 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1635 "c.relhastriggers, c.relrowsecurity, c.relforcerowsecurity, "
1636 "false AS relhasoids, c.relispartition, %s, c.reltablespace, "
1637 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
1638 "c.relpersistence, c.relreplident, am.amname\n"
1639 "FROM pg_catalog.pg_class c\n "
1640 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1641 "LEFT JOIN pg_catalog.pg_am am ON (c.relam = am.oid)\n"
1642 "WHERE c.oid = '%s';",
1644 "pg_catalog.array_to_string(c.reloptions || "
1645 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1652 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1653 "c.relhastriggers, c.relrowsecurity, c.relforcerowsecurity, "
1654 "c.relhasoids, c.relispartition, %s, c.reltablespace, "
1655 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
1656 "c.relpersistence, c.relreplident\n"
1657 "FROM pg_catalog.pg_class c\n "
1658 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1659 "WHERE c.oid = '%s';",
1661 "pg_catalog.array_to_string(c.reloptions || "
1662 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1669 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1670 "c.relhastriggers, c.relrowsecurity, c.relforcerowsecurity, "
1671 "c.relhasoids, false as relispartition, %s, c.reltablespace, "
1672 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
1673 "c.relpersistence, c.relreplident\n"
1674 "FROM pg_catalog.pg_class c\n "
1675 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1676 "WHERE c.oid = '%s';",
1678 "pg_catalog.array_to_string(c.reloptions || "
1679 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1686 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1687 "c.relhastriggers, false, false, c.relhasoids, "
1688 "false as relispartition, %s, c.reltablespace, "
1689 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
1690 "c.relpersistence, c.relreplident\n"
1691 "FROM pg_catalog.pg_class c\n "
1692 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1693 "WHERE c.oid = '%s';",
1695 "pg_catalog.array_to_string(c.reloptions || "
1696 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1703 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1704 "c.relhastriggers, false, false, c.relhasoids, "
1705 "false as relispartition, %s, c.reltablespace, "
1706 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
1707 "c.relpersistence\n"
1708 "FROM pg_catalog.pg_class c\n "
1709 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1710 "WHERE c.oid = '%s';",
1712 "pg_catalog.array_to_string(c.reloptions || "
1713 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1726 pg_log_error(
"Did not find any relation with OID %s.", oid);
1730 tableinfo.checks = atoi(
PQgetvalue(res, 0, 0));
1731 tableinfo.relkind = *(
PQgetvalue(res, 0, 1));
1732 tableinfo.hasindex = strcmp(
PQgetvalue(res, 0, 2),
"t") == 0;
1733 tableinfo.hasrules = strcmp(
PQgetvalue(res, 0, 3),
"t") == 0;
1734 tableinfo.hastriggers = strcmp(
PQgetvalue(res, 0, 4),
"t") == 0;
1735 tableinfo.rowsecurity = strcmp(
PQgetvalue(res, 0, 5),
"t") == 0;
1736 tableinfo.forcerowsecurity = strcmp(
PQgetvalue(res, 0, 6),
"t") == 0;
1737 tableinfo.hasoids = strcmp(
PQgetvalue(res, 0, 7),
"t") == 0;
1738 tableinfo.ispartition = strcmp(
PQgetvalue(res, 0, 8),
"t") == 0;
1741 tableinfo.reloftype = (strcmp(
PQgetvalue(res, 0, 11),
"") != 0) ?
1743 tableinfo.relpersistence = *(
PQgetvalue(res, 0, 12));
1750 tableinfo.relam = NULL;
1757 if (tableinfo.relkind == RELKIND_SEQUENCE)
1761 char *footers[2] = {NULL, NULL};
1766 "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n"
1767 " seqstart AS \"%s\",\n"
1768 " seqmin AS \"%s\",\n"
1769 " seqmax AS \"%s\",\n"
1770 " seqincrement AS \"%s\",\n"
1771 " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n"
1772 " seqcache AS \"%s\"\n",
1783 "FROM pg_catalog.pg_sequence\n"
1784 "WHERE seqrelid = '%s';",
1790 "SELECT 'bigint' AS \"%s\",\n"
1791 " start_value AS \"%s\",\n"
1792 " min_value AS \"%s\",\n"
1793 " max_value AS \"%s\",\n"
1794 " increment_by AS \"%s\",\n"
1795 " CASE WHEN is_cycled THEN '%s' ELSE '%s' END AS \"%s\",\n"
1796 " cache_value AS \"%s\"\n",
1817 "\n pg_catalog.quote_ident(relname) || '.' ||"
1818 "\n pg_catalog.quote_ident(attname),"
1820 "\nFROM pg_catalog.pg_class c"
1821 "\nINNER JOIN pg_catalog.pg_depend d ON c.oid=d.refobjid"
1822 "\nINNER JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace"
1823 "\nINNER JOIN pg_catalog.pg_attribute a ON ("
1824 "\n a.attrelid=c.oid AND"
1825 "\n a.attnum=d.refobjsubid)"
1826 "\nWHERE d.classid='pg_catalog.pg_class'::pg_catalog.regclass"
1827 "\n AND d.refclassid='pg_catalog.pg_class'::pg_catalog.regclass"
1828 "\n AND d.objid='%s'"
1829 "\n AND d.deptype IN ('a', 'i')",
1846 footers[0] =
psprintf(
_(
"Owned by: %s"),
1850 footers[0] =
psprintf(
_(
"Sequence for identity column: %s"),
1857 if (tableinfo.relpersistence == RELPERSISTENCE_UNLOGGED)
1859 schemaname, relationname);
1862 schemaname, relationname);
1878 if (tableinfo.relkind == RELKIND_RELATION ||
1879 tableinfo.relkind == RELKIND_VIEW ||
1880 tableinfo.relkind == RELKIND_MATVIEW ||
1881 tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
1882 tableinfo.relkind == RELKIND_COMPOSITE_TYPE ||
1883 tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
1884 show_column_details =
true;
1896 attname_col = cols++;
1898 atttype_col = cols++;
1900 if (show_column_details)
1904 ",\n (SELECT pg_catalog.pg_get_expr(d.adbin, d.adrelid, true)"
1905 "\n FROM pg_catalog.pg_attrdef d"
1906 "\n WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef)"
1907 ",\n a.attnotnull");
1908 attrdef_col = cols++;
1909 attnotnull_col = cols++;
1911 " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation");
1912 attcoll_col = cols++;
1917 attidentity_col = cols++;
1922 attgenerated_col = cols++;
1924 if (tableinfo.relkind == RELKIND_INDEX ||
1925 tableinfo.relkind == RELKIND_PARTITIONED_INDEX)
1929 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",
1933 isindexkey_col = cols++;
1936 indexdef_col = cols++;
1939 if (tableinfo.relkind == RELKIND_FOREIGN_TABLE)
1942 " '(' || pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(option_name) || ' ' || pg_catalog.quote_literal(option_value) FROM "
1943 " pg_catalog.pg_options_to_table(attfdwoptions)), ', ') || ')' END AS attfdwoptions");
1944 fdwopts_col = cols++;
1949 attstorage_col = cols++;
1954 (tableinfo.relkind == RELKIND_RELATION ||
1955 tableinfo.relkind == RELKIND_PARTITIONED_TABLE ||
1956 tableinfo.relkind == RELKIND_MATVIEW))
1959 attcompression_col = cols++;
1963 if (tableinfo.relkind == RELKIND_RELATION ||
1964 tableinfo.relkind == RELKIND_INDEX ||
1965 tableinfo.relkind == RELKIND_PARTITIONED_INDEX ||
1966 tableinfo.relkind == RELKIND_MATVIEW ||
1967 tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
1968 tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
1970 appendPQExpBufferStr(&
buf,
",\n CASE WHEN a.attstattarget=-1 THEN NULL ELSE a.attstattarget END AS attstattarget");
1971 attstattarget_col = cols++;
1978 if (tableinfo.relkind == RELKIND_RELATION ||
1979 tableinfo.relkind == RELKIND_VIEW ||
1980 tableinfo.relkind == RELKIND_MATVIEW ||
1981 tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
1982 tableinfo.relkind == RELKIND_COMPOSITE_TYPE ||
1983 tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
1986 attdescr_col = cols++;
1991 appendPQExpBuffer(&
buf,
"\nWHERE a.attrelid = '%s' AND a.attnum > 0 AND NOT a.attisdropped", oid);
2000 switch (tableinfo.relkind)
2002 case RELKIND_RELATION:
2003 if (tableinfo.relpersistence == RELPERSISTENCE_UNLOGGED)
2005 schemaname, relationname);
2008 schemaname, relationname);
2012 schemaname, relationname);
2014 case RELKIND_MATVIEW:
2016 schemaname, relationname);
2019 if (tableinfo.relpersistence == RELPERSISTENCE_UNLOGGED)
2021 schemaname, relationname);
2024 schemaname, relationname);
2026 case RELKIND_PARTITIONED_INDEX:
2027 if (tableinfo.relpersistence == RELPERSISTENCE_UNLOGGED)
2029 schemaname, relationname);
2032 schemaname, relationname);
2034 case RELKIND_TOASTVALUE:
2036 schemaname, relationname);
2038 case RELKIND_COMPOSITE_TYPE:
2040 schemaname, relationname);
2042 case RELKIND_FOREIGN_TABLE:
2044 schemaname, relationname);
2046 case RELKIND_PARTITIONED_TABLE:
2047 if (tableinfo.relpersistence == RELPERSISTENCE_UNLOGGED)
2049 schemaname, relationname);
2052 schemaname, relationname);
2057 tableinfo.relkind, schemaname, relationname);
2065 if (show_column_details)
2071 if (isindexkey_col >= 0)
2073 if (indexdef_col >= 0)
2075 if (fdwopts_col >= 0)
2077 if (attstorage_col >= 0)
2079 if (attcompression_col >= 0)
2081 if (attstattarget_col >= 0)
2083 if (attdescr_col >= 0)
2089 printTableInitialized =
true;
2091 for (
i = 0;
i < cols;
i++)
2095 for (
i = 0;
i < numrows;
i++)
2104 if (show_column_details)
2109 bool mustfree =
false;
2114 strcmp(
PQgetvalue(res,
i, attnotnull_col),
"t") == 0 ?
"not null" :
"",
2120 if (identity[0] == ATTRIBUTE_IDENTITY_ALWAYS)
2121 default_str =
"generated always as identity";
2122 else if (identity[0] == ATTRIBUTE_IDENTITY_BY_DEFAULT)
2123 default_str =
"generated by default as identity";
2124 else if (generated[0] == ATTRIBUTE_GENERATED_STORED)
2126 default_str =
psprintf(
"generated always as (%s) stored",
2130 else if (generated[0] == ATTRIBUTE_GENERATED_VIRTUAL)
2132 default_str =
psprintf(
"generated always as (%s)",
2143 if (isindexkey_col >= 0)
2145 if (indexdef_col >= 0)
2149 if (fdwopts_col >= 0)
2153 if (attstorage_col >= 0)
2159 (
storage[0] == TYPSTORAGE_MAIN ?
"main" :
2160 (
storage[0] == TYPSTORAGE_EXTENDED ?
"extended" :
2161 (
storage[0] == TYPSTORAGE_EXTERNAL ?
"external" :
2167 if (attcompression_col >= 0)
2169 char *compression =
PQgetvalue(res,
i, attcompression_col);
2173 (compression[0] ==
'l' ?
"lz4" :
2174 (compression[0] ==
'\0' ?
"" :
2180 if (attstattarget_col >= 0)
2185 if (attdescr_col >= 0)
2192 if (tableinfo.ispartition)
2198 "SELECT inhparent::pg_catalog.regclass,\n"
2199 " pg_catalog.pg_get_expr(c.relpartbound, c.oid),\n ");
2203 "false as inhdetachpending");
2208 ",\n pg_catalog.pg_get_partition_constraintdef(c.oid)");
2210 "\nFROM pg_catalog.pg_class c"
2211 " JOIN pg_catalog.pg_inherits i"
2212 " ON c.oid = inhrelid"
2213 "\nWHERE c.oid = '%s';", oid);
2220 char *parent_name =
PQgetvalue(result, 0, 0);
2226 strcmp(detached,
"t") == 0 ?
" DETACH PENDING" :
"");
2231 char *partconstraintdef = NULL;
2234 partconstraintdef =
PQgetvalue(result, 0, 3);
2236 if (partconstraintdef == NULL || partconstraintdef[0] ==
'\0')
2247 if (tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
2253 "SELECT pg_catalog.pg_get_partkeydef('%s'::pg_catalog.oid);",
2269 if (tableinfo.relkind == RELKIND_TOASTVALUE)
2275 "SELECT n.nspname, c.relname\n"
2276 "FROM pg_catalog.pg_class c"
2277 " JOIN pg_catalog.pg_namespace n"
2278 " ON n.oid = c.relnamespace\n"
2279 "WHERE reltoastrelid = '%s';", oid);
2296 if (tableinfo.relkind == RELKIND_INDEX ||
2297 tableinfo.relkind == RELKIND_PARTITIONED_INDEX)
2303 "SELECT i.indisunique, i.indisprimary, i.indisclustered, "
2305 " (NOT i.indimmediate) AND "
2306 "EXISTS (SELECT 1 FROM pg_catalog.pg_constraint "
2307 "WHERE conrelid = i.indrelid AND "
2308 "conindid = i.indexrelid AND "
2312 "condeferrable) AS condeferrable,\n"
2313 " (NOT i.indimmediate) AND "
2314 "EXISTS (SELECT 1 FROM pg_catalog.pg_constraint "
2315 "WHERE conrelid = i.indrelid AND "
2316 "conindid = i.indexrelid AND "
2320 "condeferred) AS condeferred,\n");
2333 "pg_catalog.pg_get_expr(i.indpred, i.indrelid, true)\n"
2334 "FROM pg_catalog.pg_index i, pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_am a\n"
2335 "WHERE i.indexrelid = c.oid AND c.oid = '%s' AND c.relam = a.oid\n"
2336 "AND i.indrelid = c2.oid;",
2349 char *indisunique =
PQgetvalue(result, 0, 0);
2350 char *indisprimary =
PQgetvalue(result, 0, 1);
2351 char *indisclustered =
PQgetvalue(result, 0, 2);
2355 char *indisreplident =
PQgetvalue(result, 0, 6);
2356 char *indnullsnotdistinct =
PQgetvalue(result, 0, 7);
2361 if (strcmp(indisprimary,
"t") == 0)
2363 else if (strcmp(indisunique,
"t") == 0)
2366 if (strcmp(indnullsnotdistinct,
"t") == 0)
2376 schemaname, indtable);
2378 if (strlen(indpred))
2381 if (strcmp(indisclustered,
"t") == 0)
2384 if (strcmp(indisvalid,
"t") != 0)
2387 if (strcmp(deferrable,
"t") == 0)
2390 if (strcmp(deferred,
"t") == 0)
2393 if (strcmp(indisreplident,
"t") == 0)
2401 if (tableinfo.relkind == RELKIND_INDEX)
2403 tableinfo.tablespace,
true);
2409 else if (tableinfo.relkind == RELKIND_RELATION ||
2410 tableinfo.relkind == RELKIND_MATVIEW ||
2411 tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
2412 tableinfo.relkind == RELKIND_PARTITIONED_TABLE ||
2413 tableinfo.relkind == RELKIND_PARTITIONED_INDEX ||
2414 tableinfo.relkind == RELKIND_TOASTVALUE)
2421 if (tableinfo.hasindex)
2424 "SELECT c2.relname, i.indisprimary, i.indisunique, "
2425 "i.indisclustered, i.indisvalid, "
2426 "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n "
2427 "pg_catalog.pg_get_constraintdef(con.oid, true), "
2428 "contype, condeferrable, condeferred");
2439 "\nFROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i\n"
2440 " LEFT JOIN pg_catalog.pg_constraint con ON (conrelid = i.indrelid AND conindid = i.indexrelid AND contype IN ("
2444 "WHERE c.oid = '%s' AND c.oid = i.indrelid AND i.indexrelid = c2.oid\n"
2445 "ORDER BY i.indisprimary DESC, c2.relname;",
2456 for (
i = 0;
i < tuples;
i++)
2474 const char *indexdef;
2475 const char *usingpos;
2480 else if (strcmp(
PQgetvalue(result,
i, 2),
"t") == 0)
2490 usingpos = strstr(indexdef,
" USING ");
2492 indexdef = usingpos + 7;
2525 if (tableinfo.checks)
2528 "SELECT r.conname, "
2529 "pg_catalog.pg_get_constraintdef(r.oid, true)\n"
2530 "FROM pg_catalog.pg_constraint r\n"
2531 "WHERE r.conrelid = '%s' "
2544 for (
i = 0;
i < tuples;
i++)
2559 (tableinfo.ispartition || tableinfo.relkind == RELKIND_PARTITIONED_TABLE))
2566 "SELECT conrelid = '%s'::pg_catalog.regclass AS sametable,\n"
2568 " pg_catalog.pg_get_constraintdef(oid, true) AS condef,\n"
2569 " conrelid::pg_catalog.regclass AS ontable\n"
2570 " FROM pg_catalog.pg_constraint,\n"
2571 " pg_catalog.pg_partition_ancestors('%s')\n"
2572 " WHERE conrelid = relid AND contype = " CppAsString2(CONSTRAINT_FOREIGN)
" AND conparentid = 0\n"
2573 "ORDER BY sametable DESC, conname;",
2579 "SELECT true as sametable, conname,\n"
2580 " pg_catalog.pg_get_constraintdef(r.oid, true) as condef,\n"
2581 " conrelid::pg_catalog.regclass AS ontable\n"
2582 "FROM pg_catalog.pg_constraint r\n"
2583 "WHERE r.conrelid = '%s' AND r.contype = " CppAsString2(CONSTRAINT_FOREIGN)
"\n",
2599 int i_sametable =
PQfnumber(result,
"sametable"),
2600 i_conname =
PQfnumber(result,
"conname"),
2602 i_ontable =
PQfnumber(result,
"ontable");
2605 for (
i = 0;
i < tuples;
i++)
2612 if (strcmp(
PQgetvalue(result,
i, i_sametable),
"f") == 0)
2631 "SELECT conname, conrelid::pg_catalog.regclass AS ontable,\n"
2632 " pg_catalog.pg_get_constraintdef(oid, true) AS condef\n"
2633 " FROM pg_catalog.pg_constraint c\n"
2634 " WHERE confrelid IN (SELECT pg_catalog.pg_partition_ancestors('%s')\n"
2635 " UNION ALL VALUES ('%s'::pg_catalog.regclass))\n"
2636 " AND contype = " CppAsString2(CONSTRAINT_FOREIGN)
" AND conparentid = 0\n"
2637 "ORDER BY conname;",
2643 "SELECT conname, conrelid::pg_catalog.regclass AS ontable,\n"
2644 " pg_catalog.pg_get_constraintdef(oid, true) AS condef\n"
2645 " FROM pg_catalog.pg_constraint\n"
2646 " WHERE confrelid = %s AND contype = " CppAsString2(CONSTRAINT_FOREIGN)
"\n"
2647 "ORDER BY conname;",
2659 int i_conname =
PQfnumber(result,
"conname"),
2660 i_ontable =
PQfnumber(result,
"ontable"),
2664 for (
i = 0;
i < tuples;
i++)
2682 " pol.polpermissive,\n");
2685 " 't' as polpermissive,\n");
2687 " 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"
2688 " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n"
2689 " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n"
2690 " CASE pol.polcmd\n"
2691 " WHEN 'r' THEN 'SELECT'\n"
2692 " WHEN 'a' THEN 'INSERT'\n"
2693 " WHEN 'w' THEN 'UPDATE'\n"
2694 " WHEN 'd' THEN 'DELETE'\n"
2696 "FROM pg_catalog.pg_policy pol\n"
2697 "WHERE pol.polrelid = '%s' ORDER BY 1;",
2711 if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0)
2714 if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0)
2717 if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0)
2720 if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0)
2723 if (!tableinfo.rowsecurity && tuples > 0)
2727 for (
i = 0;
i < tuples;
i++)
2763 "stxrelid::pg_catalog.regclass, "
2764 "stxnamespace::pg_catalog.regnamespace::pg_catalog.text AS nsp, "
2766 "pg_catalog.pg_get_statisticsobjdef_columns(oid) AS columns,\n"
2767 " " CppAsString2(STATS_EXT_NDISTINCT)
" = any(stxkind) AS ndist_enabled,\n"
2768 " " CppAsString2(STATS_EXT_DEPENDENCIES)
" = any(stxkind) AS deps_enabled,\n"
2769 " " CppAsString2(STATS_EXT_MCV)
" = any(stxkind) AS mcv_enabled,\n"
2771 "FROM pg_catalog.pg_statistic_ext\n"
2772 "WHERE stxrelid = '%s'\n"
2773 "ORDER BY nsp, stxname;",
2786 for (
i = 0;
i < tuples;
i++)
2788 bool gotone =
false;
2790 bool has_dependencies;
2795 has_ndistinct = (strcmp(
PQgetvalue(result,
i, 5),
"t") == 0);
2796 has_dependencies = (strcmp(
PQgetvalue(result,
i, 6),
"t") == 0);
2797 has_mcv = (strcmp(
PQgetvalue(result,
i, 7),
"t") == 0);
2814 has_all = (has_ndistinct && has_dependencies && has_mcv);
2815 has_some = (has_ndistinct || has_dependencies || has_mcv);
2817 if (has_some && !has_all)
2828 if (has_dependencies)
2861 "stxrelid::pg_catalog.regclass, "
2862 "stxnamespace::pg_catalog.regnamespace AS nsp, "
2864 " (SELECT pg_catalog.string_agg(pg_catalog.quote_ident(attname),', ')\n"
2865 " FROM pg_catalog.unnest(stxkeys) s(attnum)\n"
2866 " JOIN pg_catalog.pg_attribute a ON (stxrelid = a.attrelid AND\n"
2867 " a.attnum = s.attnum AND NOT attisdropped)) AS columns,\n"
2868 " " CppAsString2(STATS_EXT_NDISTINCT)
" = any(stxkind) AS ndist_enabled,\n"
2869 " " CppAsString2(STATS_EXT_DEPENDENCIES)
" = any(stxkind) AS deps_enabled,\n"
2870 " " CppAsString2(STATS_EXT_MCV)
" = any(stxkind) AS mcv_enabled,\n");
2877 "WHERE stxrelid = '%s'\n"
2891 for (
i = 0;
i < tuples;
i++)
2893 bool gotone =
false;
2936 if (tableinfo.hasrules && tableinfo.relkind != RELKIND_MATVIEW)
2939 "SELECT r.rulename, trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true)), "
2941 "FROM pg_catalog.pg_rewrite r\n"
2942 "WHERE r.ev_class = '%s' ORDER BY 1;",
2955 for (category = 0; category < 4; category++)
2957 have_heading =
false;
2959 for (
i = 0;
i < tuples;
i++)
2961 const char *ruledef;
2962 bool list_rule =
false;
3004 have_heading =
true;
3027 "FROM pg_catalog.pg_publication p\n"
3028 " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n"
3029 " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n"
3030 "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n"
3033 " , pg_get_expr(pr.prqual, c.oid)\n"
3034 " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n"
3035 " (SELECT string_agg(attname, ', ')\n"
3036 " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n"
3037 " pg_catalog.pg_attribute\n"
3038 " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n"
3040 "FROM pg_catalog.pg_publication p\n"
3041 " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n"
3042 " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n"
3043 "WHERE pr.prrelid = '%s'\n"
3048 "FROM pg_catalog.pg_publication p\n"
3049 "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n"
3051 oid, oid, oid, oid);
3059 "FROM pg_catalog.pg_publication p\n"
3060 "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n"
3061 "WHERE pr.prrelid = '%s'\n"
3066 "FROM pg_catalog.pg_publication p\n"
3067 "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n"
3082 for (
i = 0;
i < tuples;
i++)
3108 "SELECT c.conname, a.attname, c.connoinherit,\n"
3109 " c.conislocal, c.coninhcount <> 0,\n"
3111 "FROM pg_catalog.pg_constraint c JOIN\n"
3112 " pg_catalog.pg_attribute a ON\n"
3113 " (a.attrelid = c.conrelid AND a.attnum = c.conkey[1])\n"
3114 "WHERE c.contype = " CppAsString2(CONSTRAINT_NOTNULL)
" AND\n"
3115 " c.conrelid = '%s'::pg_catalog.regclass\n"
3116 "ORDER BY a.attnum",
3129 for (
i = 0;
i < tuples;
i++)
3131 bool islocal =
PQgetvalue(result,
i, 3)[0] ==
't';
3132 bool inherited =
PQgetvalue(result,
i, 4)[0] ==
't';
3133 bool validated =
PQgetvalue(result,
i, 5)[0] ==
't';
3140 islocal && inherited ?
_(
" (local, inherited)") :
3141 inherited ?
_(
" (inherited)") :
"",
3142 !validated ?
" NOT VALID" :
"");
3151 if ((tableinfo.relkind == RELKIND_VIEW ||
3152 tableinfo.relkind == RELKIND_MATVIEW) &&
verbose)
3157 "SELECT pg_catalog.pg_get_viewdef('%s'::pg_catalog.oid, true);",
3178 if (tableinfo.hasrules)
3181 "SELECT r.rulename, trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true))\n"
3182 "FROM pg_catalog.pg_rewrite r\n"
3183 "WHERE r.ev_class = '%s' AND r.rulename != '_RETURN' ORDER BY 1;",
3194 const char *ruledef;
3212 if (tableinfo.hastriggers)
3219 "pg_catalog.pg_get_triggerdef(t.oid, true), "
3220 "t.tgenabled, t.tgisinternal,\n");
3238 " CASE WHEN t.tgparentid != 0 THEN\n"
3239 " (SELECT u.tgrelid::pg_catalog.regclass\n"
3240 " FROM pg_catalog.pg_trigger AS u,\n"
3241 " pg_catalog.pg_partition_ancestors(t.tgrelid) WITH ORDINALITY AS a(relid, depth)\n"
3242 " WHERE u.tgname = t.tgname AND u.tgrelid = a.relid\n"
3243 " AND u.tgparentid = 0\n"
3244 " ORDER BY a.depth LIMIT 1)\n"
3245 " END AS parent\n");
3250 "FROM pg_catalog.pg_trigger t\n"
3251 "WHERE t.tgrelid = '%s' AND ",
3263 " OR EXISTS (SELECT 1 FROM pg_catalog.pg_depend WHERE objid = t.oid \n"
3264 " AND refclassid = 'pg_catalog.pg_trigger'::pg_catalog.regclass))");
3286 for (category = 0; category <= 4; category++)
3288 have_heading =
false;
3289 for (
i = 0;
i < tuples;
i++)
3293 const char *usingpos;
3294 const char *tgenabled;
3295 const char *tgisinternal;
3302 list_trigger =
false;
3306 if (*tgenabled ==
'O' || *tgenabled ==
't')
3307 list_trigger =
true;
3310 if ((*tgenabled ==
'D' || *tgenabled ==
'f') &&
3311 *tgisinternal ==
'f')
3312 list_trigger =
true;
3315 if ((*tgenabled ==
'D' || *tgenabled ==
'f') &&
3316 *tgisinternal ==
't')
3317 list_trigger =
true;
3320 if (*tgenabled ==
'A')
3321 list_trigger =
true;
3324 if (*tgenabled ==
'R')
3325 list_trigger =
true;
3328 if (list_trigger ==
false)
3332 if (have_heading ==
false)
3353 have_heading =
true;
3358 usingpos = strstr(tgdef,
" TRIGGER ");
3360 tgdef = usingpos + 9;
3379 if (tableinfo.relkind == RELKIND_RELATION ||
3380 tableinfo.relkind == RELKIND_MATVIEW ||
3381 tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
3382 tableinfo.relkind == RELKIND_PARTITIONED_TABLE ||
3383 tableinfo.relkind == RELKIND_PARTITIONED_INDEX ||
3384 tableinfo.relkind == RELKIND_TOASTVALUE)
3386 bool is_partitioned;
3391 is_partitioned = (tableinfo.relkind == RELKIND_PARTITIONED_TABLE ||
3392 tableinfo.relkind == RELKIND_PARTITIONED_INDEX);
3395 if (tableinfo.relkind == RELKIND_FOREIGN_TABLE)
3401 "SELECT s.srvname,\n"
3402 " pg_catalog.array_to_string(ARRAY(\n"
3403 " SELECT pg_catalog.quote_ident(option_name)"
3404 " || ' ' || pg_catalog.quote_literal(option_value)\n"
3405 " FROM pg_catalog.pg_options_to_table(ftoptions)), ', ')\n"
3406 "FROM pg_catalog.pg_foreign_table f,\n"
3407 " pg_catalog.pg_foreign_server s\n"
3408 "WHERE f.ftrelid = '%s' AND s.oid = f.ftserver;",
3426 if (ftoptions && ftoptions[0] !=
'\0')
3436 "SELECT c.oid::pg_catalog.regclass\n"
3437 "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n"
3438 "WHERE c.oid = i.inhparent AND i.inhrelid = '%s'\n"
3439 " AND c.relkind != " CppAsString2(RELKIND_PARTITIONED_TABLE)
3440 " AND c.relkind != " CppAsString2(RELKIND_PARTITIONED_INDEX)
3441 "\nORDER BY inhseqno;",
3449 const char *s =
_(
"Inherits");
3454 for (
i = 0;
i < tuples;
i++)
3474 "SELECT c.oid::pg_catalog.regclass, c.relkind,"
3475 " inhdetachpending,"
3476 " pg_catalog.pg_get_expr(c.relpartbound, c.oid)\n"
3477 "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n"
3478 "WHERE c.oid = i.inhrelid AND i.inhparent = '%s'\n"
3479 "ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT',"
3480 " c.oid::pg_catalog.regclass::pg_catalog.text;",
3484 "SELECT c.oid::pg_catalog.regclass, c.relkind,"
3485 " false AS inhdetachpending,"
3486 " pg_catalog.pg_get_expr(c.relpartbound, c.oid)\n"
3487 "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n"
3488 "WHERE c.oid = i.inhrelid AND i.inhparent = '%s'\n"
3489 "ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT',"
3490 " c.oid::pg_catalog.regclass::pg_catalog.text;",
3494 "SELECT c.oid::pg_catalog.regclass, c.relkind,"
3495 " false AS inhdetachpending, NULL\n"
3496 "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n"
3497 "WHERE c.oid = i.inhrelid AND i.inhparent = '%s'\n"
3498 "ORDER BY c.oid::pg_catalog.regclass::pg_catalog.text;",
3512 if (is_partitioned && tuples == 0)
3532 const char *ct = is_partitioned ?
_(
"Partitions") :
_(
"Child tables");
3535 for (
i = 0;
i < tuples;
i++)
3547 if (child_relkind == RELKIND_PARTITIONED_TABLE ||
3548 child_relkind == RELKIND_PARTITIONED_INDEX)
3550 else if (child_relkind == RELKIND_FOREIGN_TABLE)
3563 if (tableinfo.reloftype)
3570 (tableinfo.relkind == RELKIND_RELATION ||
3571 tableinfo.relkind == RELKIND_MATVIEW) &&
3577 tableinfo.relreplident != REPLICA_IDENTITY_INDEX &&
3578 ((strcmp(schemaname,
"pg_catalog") != 0 &&
3579 tableinfo.relreplident != REPLICA_IDENTITY_DEFAULT) ||
3580 (strcmp(schemaname,
"pg_catalog") == 0 &&
3581 tableinfo.relreplident != REPLICA_IDENTITY_NOTHING)))
3583 const char *s =
_(
"Replica Identity");
3587 tableinfo.relreplident == REPLICA_IDENTITY_FULL ?
"FULL" :
3588 tableinfo.relreplident == REPLICA_IDENTITY_DEFAULT ?
"NOTHING" :
3595 if (
verbose && tableinfo.relkind != RELKIND_MATVIEW && tableinfo.hasoids)
3612 tableinfo.reloptions && tableinfo.reloptions[0] !=
'\0')
3614 const char *t =
_(
"Options");
3627 if (printTableInitialized)
3650 if (relkind == RELKIND_RELATION ||
3651 relkind == RELKIND_MATVIEW ||
3652 relkind == RELKIND_INDEX ||
3653 relkind == RELKIND_PARTITIONED_TABLE ||
3654 relkind == RELKIND_PARTITIONED_INDEX ||
3655 relkind == RELKIND_TOASTVALUE)
3668 "SELECT spcname FROM pg_catalog.pg_tablespace\n"
3721 const char align =
'l';
3729 "SELECT r.rolname, r.rolsuper, r.rolinherit,\n"
3730 " r.rolcreaterole, r.rolcreatedb, r.rolcanlogin,\n"
3731 " r.rolconnlimit, r.rolvaliduntil");
3747 if (!showSystem && !pattern)
3751 NULL,
"r.rolname", NULL, NULL,
3765 attr =
pg_malloc0((nrows + 1) *
sizeof(*attr));
3775 for (
i = 0;
i < nrows;
i++)
3837 for (
i = 0;
i < nrows;
i++)
3868 "pg_catalog.array_to_string(setconfig, E'\\n') AS \"%s\"\n"
3869 "FROM pg_catalog.pg_db_role_setting s\n"
3870 "LEFT JOIN pg_catalog.pg_database d ON d.oid = setdatabase\n"
3871 "LEFT JOIN pg_catalog.pg_roles r ON r.oid = setrole\n",
3876 NULL,
"r.rolname", NULL, NULL, &havewhere, 1))
3879 NULL,
"d.datname", NULL, NULL,
3897 if (pattern && pattern2)
3898 pg_log_error(
"Did not find any settings for role \"%s\" and database \"%s\".",
3901 pg_log_error(
"Did not find any settings for role \"%s\".",
3908 myopt.
title =
_(
"List of settings");
3935 "SELECT m.rolname AS \"%s\", r.rolname AS \"%s\",\n"
3936 " pg_catalog.concat_ws(', ',\n",
3942 " CASE WHEN pam.admin_option THEN 'ADMIN' END,\n"
3943 " CASE WHEN pam.inherit_option THEN 'INHERIT' END,\n"
3944 " CASE WHEN pam.set_option THEN 'SET' END\n");
3947 " CASE WHEN pam.admin_option THEN 'ADMIN' END,\n"
3948 " CASE WHEN m.rolinherit THEN 'INHERIT' END,\n"
3953 " g.rolname AS \"%s\"\n",
3958 "FROM pg_catalog.pg_roles m\n"
3959 " JOIN pg_catalog.pg_auth_members pam ON (pam.member = m.oid)\n"
3960 " LEFT JOIN pg_catalog.pg_roles r ON (pam.roleid = r.oid)\n"
3961 " LEFT JOIN pg_catalog.pg_roles g ON (pam.grantor = g.oid)\n");
3963 if (!showSystem && !pattern)
3967 NULL,
"m.rolname", NULL, NULL,
3981 myopt.
title =
_(
"List of role grants");
4008 bool showTables = strchr(tabtypes,
't') != NULL;
4009 bool showIndexes = strchr(tabtypes,
'i') != NULL;
4010 bool showViews = strchr(tabtypes,
'v') != NULL;
4011 bool showMatViews = strchr(tabtypes,
'm') != NULL;
4012 bool showSeq = strchr(tabtypes,
's') != NULL;
4013 bool showForeign = strchr(tabtypes,
'E') != NULL;
4020 bool translate_columns[] = {
false,
false,
true,
false,
false,
false,
false,
false,
false};
4023 ntypes = showTables + showIndexes + showViews + showMatViews +
4024 showSeq + showForeign;
4027 showTables = showViews = showMatViews = showSeq = showForeign =
true;
4032 "SELECT n.nspname as \"%s\",\n"
4033 " c.relname as \"%s\",\n"
4041 " WHEN " CppAsString2(RELKIND_FOREIGN_TABLE)
" THEN '%s'"
4042 " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE)
" THEN '%s'"
4043 " WHEN " CppAsString2(RELKIND_PARTITIONED_INDEX)
" THEN '%s'"
4045 " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
4064 ",\n c2.relname as \"%s\"",
4075 ",\n CASE c.relpersistence "
4076 "WHEN " CppAsString2(RELPERSISTENCE_PERMANENT)
" THEN '%s' "
4077 "WHEN " CppAsString2(RELPERSISTENCE_TEMP)
" THEN '%s' "
4078 "WHEN " CppAsString2(RELPERSISTENCE_UNLOGGED)
" THEN '%s' "
4084 translate_columns[cols_so_far] =
true;
4096 (showTables || showMatViews || showIndexes))
4098 ",\n am.amname as \"%s\"",
4102 ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_table_size(c.oid)) as \"%s\""
4103 ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
4109 "\nFROM pg_catalog.pg_class c"
4110 "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
4113 (showTables || showMatViews || showIndexes))
4115 "\n LEFT JOIN pg_catalog.pg_am am ON am.oid = c.relam");
4119 "\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
4120 "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
4128 if (showSystem || pattern)
4140 if (showSystem || pattern)
4148 if (!showSystem && !pattern)
4150 " AND n.nspname !~ '^pg_toast'\n"
4151 " AND n.nspname <> 'information_schema'\n");
4154 "n.nspname",
"c.relname", NULL,
4155 "pg_catalog.pg_table_is_visible(c.oid)",
4179 pg_log_error(
"Did not find any relations named \"%s\".",
4181 else if (showTables)
4184 else if (showIndexes)
4190 else if (showMatViews)
4191 pg_log_error(
"Did not find any materialized views named \"%s\".",
4194 pg_log_error(
"Did not find any sequences named \"%s\".",
4196 else if (showForeign)
4197 pg_log_error(
"Did not find any foreign tables named \"%s\".",
4207 else if (showTables)
4209 else if (showIndexes)
4213 else if (showMatViews)
4217 else if (showForeign)
4226 (ntypes != 1) ?
_(
"List of relations") :
4227 (showTables) ?
_(
"List of tables") :
4228 (showIndexes) ?
_(
"List of indexes") :
4229 (showViews) ?
_(
"List of views") :
4230 (showMatViews) ?
_(
"List of materialized views") :
4231 (showSeq) ?
_(
"List of sequences") :
4232 (showForeign) ?
_(
"List of foreign tables") :
4263 bool showTables = strchr(reltypes,
't') != NULL;
4264 bool showIndexes = strchr(reltypes,
'i') != NULL;
4265 bool showNested = strchr(reltypes,
'n') != NULL;
4270 bool translate_columns[] = {
false,
false,
false,
false,
false,
false,
false,
false,
false,
false};
4271 const char *tabletitle;
4272 bool mixed_output =
false;
4281 pg_log_error(
"The server (version %s) does not support declarative table partitioning.",
4283 sverbuf,
sizeof(sverbuf)));
4288 if (!showTables && !showIndexes)
4289 showTables = showIndexes =
true;
4291 if (showIndexes && !showTables)
4292 tabletitle =
_(
"List of partitioned indexes");
4293 else if (showTables && !showIndexes)
4294 tabletitle =
_(
"List of partitioned tables");
4298 tabletitle =
_(
"List of partitioned relations");
4299 mixed_output =
true;
4305 "SELECT n.nspname as \"%s\",\n"
4306 " c.relname as \"%s\",\n"
4307 " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
4315 ",\n CASE c.relkind"
4316 " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE)
" THEN '%s'"
4317 " WHEN " CppAsString2(RELKIND_PARTITIONED_INDEX)
" THEN '%s'"
4323 translate_columns[3] =
true;
4326 if (showNested || pattern)
4328 ",\n inh.inhparent::pg_catalog.regclass as \"%s\"",
4333 ",\n c2.oid::pg_catalog.regclass as \"%s\"",
4348 ",\n s.dps as \"%s\"",
4351 ",\n s.tps as \"%s\"",
4357 ",\n s.tps as \"%s\"",
4361 ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
4366 "\nFROM pg_catalog.pg_class c"
4367 "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
4371 "\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
4372 "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
4374 if (showNested || pattern)
4376 "\n LEFT JOIN pg_catalog.pg_inherits inh ON c.oid = inh.inhrelid");
4381 "\n LEFT JOIN pg_catalog.pg_am am ON c.relam = am.oid");
4386 ",\n LATERAL (WITH RECURSIVE d\n"
4387 " AS (SELECT inhrelid AS oid, 1 AS level\n"
4388 " FROM pg_catalog.pg_inherits\n"
4389 " WHERE inhparent = c.oid\n"
4391 " SELECT inhrelid, level + 1\n"
4392 " FROM pg_catalog.pg_inherits i\n"
4393 " JOIN d ON i.inhparent = d.oid)\n"
4394 " SELECT pg_catalog.pg_size_pretty(sum(pg_catalog.pg_table_size("
4395 "d.oid))) AS tps,\n"
4396 " pg_catalog.pg_size_pretty(sum("
4397 "\n CASE WHEN d.level = 1"
4398 " THEN pg_catalog.pg_table_size(d.oid) ELSE 0 END)) AS dps\n"
4405 ",\n LATERAL (SELECT pg_catalog.pg_size_pretty(sum("
4406 "\n CASE WHEN ppt.isleaf AND ppt.level = 1"
4407 "\n THEN pg_catalog.pg_table_size(ppt.relid)"
4408 " ELSE 0 END)) AS dps"
4409 ",\n pg_catalog.pg_size_pretty(sum("
4410 "pg_catalog.pg_table_size(ppt.relid))) AS tps"
4411 "\n FROM pg_catalog.pg_partition_tree(c.oid) ppt) s");
4424 " AND NOT c.relispartition\n" :
"");
4428 " AND n.nspname !~ '^pg_toast'\n"
4429 " AND n.nspname <> 'information_schema'\n");
4432 "n.nspname",
"c.relname", NULL,
4433 "pg_catalog.pg_table_is_visible(c.oid)",
4441 mixed_output ?
"\"Type\" DESC, " :
"",
4442 showNested || pattern ?
"\"Parent name\" NULLS FIRST, " :
"");
4480 "SELECT l.lanname AS \"%s\",\n"
4481 " pg_catalog.pg_get_userbyid(l.lanowner) as \"%s\",\n"
4482 " l.lanpltrusted AS \"%s\"",
4490 ",\n NOT l.lanispl AS \"%s\",\n"
4491 " l.lanplcallfoid::pg_catalog.regprocedure AS \"%s\",\n"
4492 " l.lanvalidator::pg_catalog.regprocedure AS \"%s\",\n "
4493 "l.laninline::pg_catalog.regprocedure AS \"%s\",\n ",
4502 ",\n d.description AS \"%s\""
4503 "\nFROM pg_catalog.pg_language l\n"
4504 "LEFT JOIN pg_catalog.pg_description d\n"
4505 " ON d.classoid = l.tableoid AND d.objoid = l.oid\n"
4506 " AND d.objsubid = 0\n",
4512 NULL,
"l.lanname", NULL, NULL,
4520 if (!showSystem && !pattern)
4531 myopt.
title =
_(
"List of languages");
4556 "SELECT n.nspname as \"%s\",\n"
4557 " t.typname as \"%s\",\n"
4558 " pg_catalog.format_type(t.typbasetype, t.typtypmod) as \"%s\",\n"
4559 " (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type bt\n"
4560 " WHERE c.oid = t.typcollation AND bt.oid = t.typbasetype AND t.typcollation <> bt.typcollation) as \"%s\",\n"
4561 " CASE WHEN t.typnotnull THEN 'not null' END as \"%s\",\n"
4562 " t.typdefault as \"%s\",\n"
4563 " pg_catalog.array_to_string(ARRAY(\n"
4564 " SELECT pg_catalog.pg_get_constraintdef(r.oid, true) FROM pg_catalog.pg_constraint r WHERE t.oid = r.contypid AND r.contype = " CppAsString2(CONSTRAINT_CHECK)
" ORDER BY r.conname\n"
4565 " ), ' ') as \"%s\"",
4579 ",\n d.description as \"%s\"",
4584 "\nFROM pg_catalog.pg_type t\n"
4585 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
4589 " LEFT JOIN pg_catalog.pg_description d "
4590 "ON d.classoid = t.tableoid AND d.objoid = t.oid "
4591 "AND d.objsubid = 0\n");
4595 if (!showSystem && !pattern)
4597 " AND n.nspname <> 'information_schema'\n");
4600 "n.nspname",
"t.typname", NULL,
4601 "pg_catalog.pg_type_is_visible(t.oid)",
4615 myopt.
title =
_(
"List of domains");
4635 static const bool translate_columns[] =
4636 {
false,
false,
false,
false,
true,
false};
4641 "SELECT n.nspname AS \"%s\",\n"
4642 " c.conname AS \"%s\",\n"
4643 " pg_catalog.pg_encoding_to_char(c.conforencoding) AS \"%s\",\n"
4644 " pg_catalog.pg_encoding_to_char(c.contoencoding) AS \"%s\",\n"
4645 " CASE WHEN c.condefault THEN '%s'\n"
4646 " ELSE '%s' END AS \"%s\"",
4656 ",\n d.description AS \"%s\"",
4660 "\nFROM pg_catalog.pg_conversion c\n"
4661 " JOIN pg_catalog.pg_namespace n "
4662 "ON n.oid = c.connamespace\n");
4666 "LEFT JOIN pg_catalog.pg_description d "
4667 "ON d.classoid = c.tableoid\n"
4668 " AND d.objoid = c.oid "
4669 "AND d.objsubid = 0\n");
4673 if (!showSystem && !pattern)
4675 " AND n.nspname <> 'information_schema'\n");
4678 "n.nspname",
"c.conname", NULL,
4679 "pg_catalog.pg_conversion_is_visible(c.oid)",
4693 myopt.
title =
_(
"List of conversions");
4719 "SELECT s.name AS \"%s\", "
4720 "pg_catalog.current_setting(s.name) AS \"%s\"",
4727 ", s.vartype AS \"%s\", s.context AS \"%s\", ",
4741 " LEFT JOIN pg_catalog.pg_parameter_acl p\n"
4742 " ON pg_catalog.lower(s.name) = p.parname\n");
4747 NULL,
"pg_catalog.lower(s.name)", NULL,
4751 " s.setting IS DISTINCT FROM s.boot_val\n");
4761 myopt.
title =
_(
"List of configuration parameters");
4763 myopt.
title =
_(
"List of non-default configuration parameters");
4783 static const bool translate_columns[] =
4784 {
false,
false,
false,
true,
false,
false,
false};
4790 pg_log_error(
"The server (version %s) does not support event triggers.",
4792 sverbuf,
sizeof(sverbuf)));
4799 "SELECT evtname as \"%s\", "
4800 "evtevent as \"%s\", "
4801 "pg_catalog.pg_get_userbyid(e.evtowner) as \"%s\",\n"
4802 " case evtenabled when 'O' then '%s'"
4803 " when 'R' then '%s'"
4804 " when 'A' then '%s'"
4805 " when 'D' then '%s' end as \"%s\",\n"
4806 " e.evtfoid::pg_catalog.regproc as \"%s\", "
4807 "pg_catalog.array_to_string(array(select x"
4808 " from pg_catalog.unnest(evttags) as t(x)), ', ') as \"%s\"",
4821 ",\npg_catalog.obj_description(e.oid, 'pg_event_trigger') as \"%s\"",
4824 "\nFROM pg_catalog.pg_event_trigger e ");
4827 NULL,
"evtname", NULL, NULL,
4841 myopt.
title =
_(
"List of event triggers");
4868 pg_log_error(
"The server (version %s) does not support extended statistics.",
4870 sverbuf,
sizeof(sverbuf)));
4877 "es.stxnamespace::pg_catalog.regnamespace::pg_catalog.text AS \"%s\", \n"
4878 "es.stxname AS \"%s\", \n",
4884 "pg_catalog.format('%%s FROM %%s', \n"
4885 " pg_catalog.pg_get_statisticsobjdef_columns(es.oid), \n"
4886 " es.stxrelid::pg_catalog.regclass) AS \"%s\"",
4890 "pg_catalog.format('%%s FROM %%s', \n"
4891 " (SELECT pg_catalog.string_agg(pg_catalog.quote_ident(a.attname),', ') \n"
4892 " FROM pg_catalog.unnest(es.stxkeys) s(attnum) \n"
4893 " JOIN pg_catalog.pg_attribute a \n"
4894 " ON (es.stxrelid = a.attrelid \n"
4895 " AND a.attnum = s.attnum \n"
4896 " AND NOT a.attisdropped)), \n"
4897 "es.stxrelid::pg_catalog.regclass) AS \"%s\"",
4901 ",\nCASE WHEN " CppAsString2(STATS_EXT_NDISTINCT)
" = any(es.stxkind) THEN 'defined' \n"
4903 "CASE WHEN " CppAsString2(STATS_EXT_DEPENDENCIES)
" = any(es.stxkind) THEN 'defined' \n"
4914 ",\nCASE WHEN " CppAsString2(STATS_EXT_MCV)
" = any(es.stxkind) THEN 'defined' \n"
4920 " \nFROM pg_catalog.pg_statistic_ext es \n");
4924 "es.stxnamespace::pg_catalog.regnamespace::pg_catalog.text",
"es.stxname",
4925 NULL,
"pg_catalog.pg_statistics_obj_is_visible(es.oid)",
4939 myopt.
title =
_(
"List of extended statistics");
4959 static const bool translate_columns[] = {
false,
false,
false,
true,
true,
false};
4964 "SELECT pg_catalog.format_type(castsource, NULL) AS \"%s\",\n"
4965 " pg_catalog.format_type(casttarget, NULL) AS \"%s\",\n",
4975 " CASE WHEN c.castmethod = '%c' THEN '(binary coercible)'\n"
4976 " WHEN c.castmethod = '%c' THEN '(with inout)'\n"
4978 " END AS \"%s\",\n",
4979 COERCION_METHOD_BINARY,
4980 COERCION_METHOD_INOUT,
4984 " CASE WHEN c.castcontext = '%c' THEN '%s'\n"
4985 " WHEN c.castcontext = '%c' THEN '%s'\n"
4988 COERCION_CODE_EXPLICIT,
4990 COERCION_CODE_ASSIGNMENT,
4997 ",\n CASE WHEN p.proleakproof THEN '%s'\n"
5000 " d.description AS \"%s\"",
5011 "\nFROM pg_catalog.pg_cast c LEFT JOIN pg_catalog.pg_proc p\n"
5012 " ON c.castfunc = p.oid\n"
5013 " LEFT JOIN pg_catalog.pg_type ts\n"
5014 " ON c.castsource = ts.oid\n"
5015 " LEFT JOIN pg_catalog.pg_namespace ns\n"
5016 " ON ns.oid = ts.typnamespace\n"
5017 " LEFT JOIN pg_catalog.pg_type tt\n"
5018 " ON c.casttarget = tt.oid\n"
5019 " LEFT JOIN pg_catalog.pg_namespace nt\n"
5020 " ON nt.oid = tt.typnamespace\n");
5024 " LEFT JOIN pg_catalog.pg_description d\n"
5025 " ON d.classoid = c.tableoid AND d.objoid = "
5026 "c.oid AND d.objsubid = 0\n");
5035 "ns.nspname",
"ts.typname",
5036 "pg_catalog.format_type(ts.oid, NULL)",
5037 "pg_catalog.pg_type_is_visible(ts.oid)",
5044 "nt.nspname",
"tt.typname",
5045 "pg_catalog.format_type(tt.oid, NULL)",
5046 "pg_catalog.pg_type_is_visible(tt.oid)",
5057 myopt.
title =
_(
"List of casts");
5083 static const bool translate_columns[] = {
false,
false,
false,
false,
false,
false,
false,
true,
false};
5089 " n.nspname AS \"%s\",\n"
5090 " c.collname AS \"%s\",\n",
5096 " CASE c.collprovider "
5097 "WHEN " CppAsString2(COLLPROVIDER_DEFAULT)
" THEN 'default' "
5098 "WHEN " CppAsString2(COLLPROVIDER_BUILTIN)
" THEN 'builtin' "
5099 "WHEN " CppAsString2(COLLPROVIDER_LIBC)
" THEN 'libc' "
5105 " 'libc' AS \"%s\",\n",
5109 " c.collcollate AS \"%s\",\n"
5110 " c.collctype AS \"%s\",\n",
5116 " c.colllocale AS \"%s\",\n",
5120 " c.colliculocale AS \"%s\",\n",
5124 " c.collcollate AS \"%s\",\n",
5129 " c.collicurules AS \"%s\",\n",
5133 " NULL AS \"%s\",\n",
5138 " CASE WHEN c.collisdeterministic THEN '%s' ELSE '%s' END AS \"%s\"",
5149 ",\n pg_catalog.obj_description(c.oid, 'pg_collation') AS \"%s\"",
5153 "\nFROM pg_catalog.pg_collation c, pg_catalog.pg_namespace n\n"
5154 "WHERE n.oid = c.collnamespace\n");
5156 if (!showSystem && !pattern)
5158 " AND n.nspname <> 'information_schema'\n");
5166 appendPQExpBufferStr(&
buf,
" AND c.collencoding IN (-1, pg_catalog.pg_char_to_encoding(pg_catalog.getdatabaseencoding()))\n");
5169 "n.nspname",
"c.collname", NULL,
5170 "pg_catalog.pg_collation_is_visible(c.oid)",
5184 myopt.
title =
_(
"List of collations");
5206 int pub_schema_tuples = 0;
5207 char **footers = NULL;
5211 "SELECT n.nspname AS \"%s\",\n"
5212 " pg_catalog.pg_get_userbyid(n.nspowner) AS \"%s\"",
5221 ",\n pg_catalog.obj_description(n.oid, 'pg_namespace') AS \"%s\"",
5226 "\nFROM pg_catalog.pg_namespace n\n");
5228 if (!showSystem && !pattern)
5230 "WHERE n.nspname !~ '^pg_' AND n.nspname <> 'information_schema'\n");
5233 !showSystem && !pattern,
false,
5234 NULL,
"n.nspname", NULL,
5245 myopt.
title =
_(
"List of schemas");
5255 "FROM pg_catalog.pg_publication p\n"
5256 " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n"
5257 " JOIN pg_catalog.pg_namespace n ON n.oid = pn.pnnspid \n"
5258 "WHERE n.nspname = '%s'\n"
5267 if (pub_schema_tuples > 0)
5274 footers = (
char **)
pg_malloc((1 + pub_schema_tuples + 1) *
sizeof(
char *));
5278 for (
i = 0;
i < pub_schema_tuples;
i++)
5286 footers[
i + 1] = NULL;
5301 char **footer = NULL;
5303 for (footer = footers; *footer; footer++)
5335 " n.nspname as \"%s\",\n"
5336 " p.prsname as \"%s\",\n"
5337 " pg_catalog.obj_description(p.oid, 'pg_ts_parser') as \"%s\"\n"
5338 "FROM pg_catalog.pg_ts_parser p\n"
5339 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.prsnamespace\n",
5346 "n.nspname",
"p.prsname", NULL,
5347 "pg_catalog.pg_ts_parser_is_visible(p.oid)",
5361 myopt.
title =
_(
"List of text search parsers");
5386 "FROM pg_catalog.pg_ts_parser p\n"
5387 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.prsnamespace\n"
5391 "n.nspname",
"p.prsname", NULL,
5392 "pg_catalog.pg_ts_parser_is_visible(p.oid)",
5411 pg_log_error(
"Did not find any text search parser named \"%s\".",
5423 const char *nspname = NULL;
5424 const char *prsname;
5455 static const bool translate_columns[] = {
true,
false,
false};
5460 "SELECT '%s' AS \"%s\",\n"
5461 " p.prsstart::pg_catalog.regproc AS \"%s\",\n"
5462 " pg_catalog.obj_description(p.prsstart, 'pg_proc') as \"%s\"\n"
5463 " FROM pg_catalog.pg_ts_parser p\n"
5464 " WHERE p.oid = '%s'\n"
5467 " p.prstoken::pg_catalog.regproc,\n"
5468 " pg_catalog.obj_description(p.prstoken, 'pg_proc')\n"
5469 " FROM pg_catalog.pg_ts_parser p\n"
5470 " WHERE p.oid = '%s'\n"
5473 " p.prsend::pg_catalog.regproc,\n"
5474 " pg_catalog.obj_description(p.prsend, 'pg_proc')\n"
5475 " FROM pg_catalog.pg_ts_parser p\n"
5476 " WHERE p.oid = '%s'\n"
5479 " p.prsheadline::pg_catalog.regproc,\n"
5480 " pg_catalog.obj_description(p.prsheadline, 'pg_proc')\n"
5481 " FROM pg_catalog.pg_ts_parser p\n"
5482 " WHERE p.oid = '%s'\n"
5485 " p.prslextype::pg_catalog.regproc,\n"
5486 " pg_catalog.obj_description(p.prslextype, 'pg_proc')\n"
5487 " FROM pg_catalog.pg_ts_parser p\n"
5488 " WHERE p.oid = '%s';",
5528 "SELECT t.alias as \"%s\",\n"
5529 " t.description as \"%s\"\n"
5530 "FROM pg_catalog.ts_token_type( '%s'::pg_catalog.oid ) as t\n"
5579 " n.nspname as \"%s\",\n"
5580 " d.dictname as \"%s\",\n",
5587 " ( SELECT COALESCE(nt.nspname, '(null)')::pg_catalog.text || '.' || t.tmplname FROM\n"
5588 " pg_catalog.pg_ts_template t\n"
5589 " LEFT JOIN pg_catalog.pg_namespace nt ON nt.oid = t.tmplnamespace\n"
5590 " WHERE d.dicttemplate = t.oid ) AS \"%s\",\n"
5591 " d.dictinitoption as \"%s\",\n",
5597 " pg_catalog.obj_description(d.oid, 'pg_ts_dict') as \"%s\"\n",
5601 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.dictnamespace\n");
5604 "n.nspname",
"d.dictname", NULL,
5605 "pg_catalog.pg_ts_dict_is_visible(d.oid)",
5619 myopt.
title =
_(
"List of text search dictionaries");
5645 " n.nspname AS \"%s\",\n"
5646 " t.tmplname AS \"%s\",\n"
5647 " t.tmplinit::pg_catalog.regproc AS \"%s\",\n"
5648 " t.tmpllexize::pg_catalog.regproc AS \"%s\",\n"
5649 " pg_catalog.obj_description(t.oid, 'pg_ts_template') AS \"%s\"\n",
5658 " n.nspname AS \"%s\",\n"
5659 " t.tmplname AS \"%s\",\n"
5660 " pg_catalog.obj_description(t.oid, 'pg_ts_template') AS \"%s\"\n",
5666 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.tmplnamespace\n");
5669 "n.nspname",
"t.tmplname", NULL,
5670 "pg_catalog.pg_ts_template_is_visible(t.oid)",
5684 myopt.
title =
_(
"List of text search templates");
5712 " n.nspname as \"%s\",\n"
5713 " c.cfgname as \"%s\",\n"
5714 " pg_catalog.obj_description(c.oid, 'pg_ts_config') as \"%s\"\n"
5715 "FROM pg_catalog.pg_ts_config c\n"
5716 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.cfgnamespace\n",
5723 "n.nspname",
"c.cfgname", NULL,
5724 "pg_catalog.pg_ts_config_is_visible(c.oid)",
5738 myopt.
title =
_(
"List of text search configurations");
5757 "SELECT c.oid, c.cfgname,\n"
5760 " np.nspname as pnspname\n"
5761 "FROM pg_catalog.pg_ts_config c\n"
5762 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.cfgnamespace,\n"
5763 " pg_catalog.pg_ts_parser p\n"
5764 " LEFT JOIN pg_catalog.pg_namespace np ON np.oid = p.prsnamespace\n"
5765 "WHERE p.oid = c.cfgparser\n"
5769 "n.nspname",
"c.cfgname", NULL,
5770 "pg_catalog.pg_ts_config_is_visible(c.oid)",
5789 pg_log_error(
"Did not find any text search configuration named \"%s\".",
5792 pg_log_error(
"Did not find any text search configurations.");
5801 const char *cfgname;
5802 const char *nspname = NULL;
5803 const char *prsname;
5804 const char *pnspname = NULL;
5833 const char *pnspname,
const char *prsname)
5844 " ( SELECT t.alias FROM\n"
5845 " pg_catalog.ts_token_type(c.cfgparser) AS t\n"
5846 " WHERE t.tokid = m.maptokentype ) AS \"%s\",\n"
5847 " pg_catalog.btrim(\n"
5848 " ARRAY( SELECT mm.mapdict::pg_catalog.regdictionary\n"
5849 " FROM pg_catalog.pg_ts_config_map AS mm\n"
5850 " WHERE mm.mapcfg = m.mapcfg AND mm.maptokentype = m.maptokentype\n"
5851 " ORDER BY mapcfg, maptokentype, mapseqno\n"
5852 " ) :: pg_catalog.text,\n"
5853 " '{}') AS \"%s\"\n"
5854 "FROM pg_catalog.pg_ts_config AS c, pg_catalog.pg_ts_config_map AS m\n"
5855 "WHERE c.oid = '%s' AND m.mapcfg = c.oid\n"
5856 "GROUP BY m.mapcfg, m.maptokentype, c.cfgparser\n"
5911 "SELECT fdw.fdwname AS \"%s\",\n"
5912 " pg_catalog.pg_get_userbyid(fdw.fdwowner) AS \"%s\",\n"
5913 " fdw.fdwhandler::pg_catalog.regproc AS \"%s\",\n"
5914 " fdw.fdwvalidator::pg_catalog.regproc AS \"%s\"",
5925 ",\n CASE WHEN fdwoptions IS NULL THEN '' ELSE "
5926 " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
5927 " pg_catalog.quote_ident(option_name) || ' ' || "
5928 " pg_catalog.quote_literal(option_value) FROM "
5929 " pg_catalog.pg_options_to_table(fdwoptions)), ', ') || ')' "
5931 ",\n d.description AS \"%s\" ",
5940 "LEFT JOIN pg_catalog.pg_description d\n"
5941 " ON d.classoid = fdw.tableoid "
5942 "AND d.objoid = fdw.oid AND d.objsubid = 0\n");
5945 NULL,
"fdwname", NULL, NULL,
5959 myopt.
title =
_(
"List of foreign-data wrappers");
5982 "SELECT s.srvname AS \"%s\",\n"
5983 " pg_catalog.pg_get_userbyid(s.srvowner) AS \"%s\",\n"
5984 " f.fdwname AS \"%s\"",
5995 " s.srvtype AS \"%s\",\n"
5996 " s.srvversion AS \"%s\",\n"
5997 " CASE WHEN srvoptions IS NULL THEN '' ELSE "
5998 " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
5999 " pg_catalog.quote_ident(option_name) || ' ' || "
6000 " pg_catalog.quote_literal(option_value) FROM "
6001 " pg_catalog.pg_options_to_table(srvoptions)), ', ') || ')' "
6003 " d.description AS \"%s\"",
6011 "\nFROM pg_catalog.pg_foreign_server s\n"
6012 " JOIN pg_catalog.pg_foreign_data_wrapper f ON f.oid=s.srvfdw\n");
6016 "LEFT JOIN pg_catalog.pg_description d\n "
6017 "ON d.classoid = s.tableoid AND d.objoid = s.oid "
6018 "AND d.objsubid = 0\n");
6021 NULL,
"s.srvname", NULL, NULL,
6035 myopt.
title =
_(
"List of foreign servers");
6058 "SELECT um.srvname AS \"%s\",\n"
6059 " um.usename AS \"%s\"",
6065 ",\n CASE WHEN umoptions IS NULL THEN '' ELSE "
6066 " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
6067 " pg_catalog.quote_ident(option_name) || ' ' || "
6068 " pg_catalog.quote_literal(option_value) FROM "
6069 " pg_catalog.pg_options_to_table(umoptions)), ', ') || ')' "
6076 NULL,
"um.srvname",
"um.usename", NULL,
6090 myopt.
title =
_(
"List of user mappings");
6113 "SELECT n.nspname AS \"%s\",\n"
6114 " c.relname AS \"%s\",\n"
6115 " s.srvname AS \"%s\"",
6122 ",\n CASE WHEN ftoptions IS NULL THEN '' ELSE "
6123 " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
6124 " pg_catalog.quote_ident(option_name) || ' ' || "
6125 " pg_catalog.quote_literal(option_value) FROM "
6126 " pg_catalog.pg_options_to_table(ftoptions)), ', ') || ')' "
6128 " d.description AS \"%s\"",
6133 "\nFROM pg_catalog.pg_foreign_table ft\n"
6134 " INNER JOIN pg_catalog.pg_class c"
6135 " ON c.oid = ft.ftrelid\n"
6136 " INNER JOIN pg_catalog.pg_namespace n"
6137 " ON n.oid = c.relnamespace\n"
6138 " INNER JOIN pg_catalog.pg_foreign_server s"
6139 " ON s.oid = ft.ftserver\n");
6142 " LEFT JOIN pg_catalog.pg_description d\n"
6143 " ON d.classoid = c.tableoid AND "
6144 "d.objoid = c.oid AND d.objsubid = 0\n");
6147 "n.nspname",
"c.relname", NULL,
6148 "pg_catalog.pg_table_is_visible(c.oid)",
6162 myopt.
title =
_(
"List of foreign tables");
6185 "SELECT e.extname AS \"%s\", "
6186 "e.extversion AS \"%s\", ae.default_version AS \"%s\","
6187 "n.nspname AS \"%s\", d.description AS \"%s\"\n"
6188 "FROM pg_catalog.pg_extension e "
6189 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = e.extnamespace "
6190 "LEFT JOIN pg_catalog.pg_description d ON d.objoid = e.oid "
6191 "LEFT JOIN pg_catalog.pg_available_extensions() ae(name, default_version, comment) ON ae.name = e.extname "
6192 "AND d.classoid = 'pg_catalog.pg_extension'::pg_catalog.regclass\n",
6201 NULL,
"e.extname", NULL,
6216 myopt.
title =
_(
"List of installed extensions");
6239 "SELECT e.extname, e.oid\n"
6240 "FROM pg_catalog.pg_extension e\n");
6244 NULL,
"e.extname", NULL,
6264 pg_log_error(
"Did not find any extension named \"%s\".",
6275 const char *extname;
6307 "SELECT pg_catalog.pg_describe_object(classid, objid, 0) AS \"%s\"\n"
6308 "FROM pg_catalog.pg_depend\n"
6309 "WHERE refclassid = 'pg_catalog.pg_extension'::pg_catalog.regclass AND refobjid = '%s' AND deptype = 'e'\n"
6343 bool force_escape,
const char *schemavar,
6344 const char *namevar,
const char *altnamevar,
6345 const char *visibilityrule,
bool *added_clause,
6354 schemavar, namevar, altnamevar,
6355 visibilityrule, &dbbuf, &dotcnt);
6356 if (added_clause != NULL)
6357 *added_clause = added;
6359 if (dotcnt >= maxparts)
6361 pg_log_error(
"improper qualified name (too many dotted names): %s",
6366 if (maxparts > 1 && dotcnt == maxparts - 1)
6370 pg_log_error(
"You are currently not connected to a database.");
6375 pg_log_error(
"cross-database references are not implemented: %s",
6400 static const bool translate_columns[] = {
false,
false,
false,
false,
false,
false,
false,
false,
false};
6406 pg_log_error(
"The server (version %s) does not support publications.",
6408 sverbuf,
sizeof(sverbuf)));
6415 "SELECT pubname AS \"%s\",\n"
6416 " pg_catalog.pg_get_userbyid(pubowner) AS \"%s\",\n"
6417 " puballtables AS \"%s\",\n"
6418 " pubinsert AS \"%s\",\n"
6419 " pubupdate AS \"%s\",\n"
6420 " pubdelete AS \"%s\"",
6429 ",\n pubtruncate AS \"%s\"",
6433 ",\n (CASE pubgencols\n"
6434 " WHEN '%c' THEN 'none'\n"
6435 " WHEN '%c' THEN 'stored'\n"
6437 PUBLISH_GENCOLS_NONE,
6438 PUBLISH_GENCOLS_STORED,
6442 ",\n pubviaroot AS \"%s\"",
6446 "\nFROM pg_catalog.pg_publication\n");
6449 NULL,
"pubname", NULL,
6464 myopt.
title =
_(
"List of publications");
6496 for (
i = 0;
i < count;
i++)
6531 bool has_pubtruncate;
6532 bool has_pubgencols;
6533 bool has_pubviaroot;
6542 pg_log_error(
"The server (version %s) does not support publications.",
6544 sverbuf,
sizeof(sverbuf)));
6555 "SELECT oid, pubname,\n"
6556 " pg_catalog.pg_get_userbyid(pubowner) AS owner,\n"
6557 " puballtables, pubinsert, pubupdate, pubdelete");
6558 if (has_pubtruncate)
6563 ", false AS pubtruncate");
6567 ", (CASE pubgencols\n"
6568 " WHEN '%c' THEN 'none'\n"
6569 " WHEN '%c' THEN 'stored'\n"
6570 " END) AS \"%s\"\n",
6571 PUBLISH_GENCOLS_NONE,
6572 PUBLISH_GENCOLS_STORED,
6576 ", 'none' AS pubgencols");
6583 ", false AS pubviaroot");
6586 "\nFROM pg_catalog.pg_publication\n");
6589 NULL,
"pubname", NULL,
6611 pg_log_error(
"Did not find any publication named \"%s\".",
6624 const char align =
'l';
6629 bool puballtables = strcmp(
PQgetvalue(res,
i, 3),
"t") == 0;
6632 if (has_pubtruncate)
6648 if (has_pubtruncate)
6660 if (has_pubtruncate)
6671 "SELECT n.nspname, c.relname");
6675 ", pg_get_expr(pr.prqual, c.oid)");
6677 ", (CASE WHEN pr.prattrs IS NOT NULL THEN\n"
6678 " pg_catalog.array_to_string("
6679 " ARRAY(SELECT attname\n"
6681 " pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n"
6682 " pg_catalog.pg_attribute\n"
6683 " WHERE attrelid = c.oid AND attnum = prattrs[s]), ', ')\n"
6690 "\nFROM pg_catalog.pg_class c,\n"
6691 " pg_catalog.pg_namespace n,\n"
6692 " pg_catalog.pg_publication_rel pr\n"
6693 "WHERE c.relnamespace = n.oid\n"
6694 " AND c.oid = pr.prrelid\n"
6695 " AND pr.prpubid = '%s'\n"
6696 "ORDER BY 1,2", pubid);
6704 "SELECT n.nspname\n"
6705 "FROM pg_catalog.pg_namespace n\n"
6706 " JOIN pg_catalog.pg_publication_namespace pn ON n.oid = pn.pnnspid\n"
6707 "WHERE pn.pnpubid = '%s'\n"
6708 "ORDER BY 1", pubid);
6746 static const bool translate_columns[] = {
false,
false,
false,
false,
6747 false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
6754 pg_log_error(
"The server (version %s) does not support subscriptions.",
6756 sverbuf,
sizeof(sverbuf)));
6763 "SELECT subname AS \"%s\"\n"
6764 ", pg_catalog.pg_get_userbyid(subowner) AS \"%s\"\n"
6765 ", subenabled AS \"%s\"\n"
6766 ", subpublications AS \"%s\"\n",
6778 ", subbinary AS \"%s\"\n",
6783 ", (CASE substream\n"
6784 " WHEN " CppAsString2(LOGICALREP_STREAM_OFF)
" THEN 'off'\n"
6785 " WHEN " CppAsString2(LOGICALREP_STREAM_ON)
" THEN 'on'\n"
6786 " WHEN " CppAsString2(LOGICALREP_STREAM_PARALLEL)
" THEN 'parallel'\n"
6787 " END) AS \"%s\"\n",
6791 ", substream AS \"%s\"\n",
6798 ", subtwophasestate AS \"%s\"\n"
6799 ", subdisableonerr AS \"%s\"\n",
6805 ", suborigin AS \"%s\"\n"
6806 ", subpasswordrequired AS \"%s\"\n"
6807 ", subrunasowner AS \"%s\"\n",
6814 ", subfailover AS \"%s\"\n",
6818 ", subsynccommit AS \"%s\"\n"
6819 ", subconninfo AS \"%s\"\n",
6826 ", subskiplsn AS \"%s\"\n",
6832 "FROM pg_catalog.pg_subscription\n"
6833 "WHERE subdbid = (SELECT oid\n"
6834 " FROM pg_catalog.pg_database\n"
6835 " WHERE datname = pg_catalog.current_database())");
6838 NULL,
"subname", NULL,
6853 myopt.
title =
_(
"List of subscriptions");
6879 " WHEN pg_catalog.array_length(%s, 1) = 0 THEN '%s'"
6880 " ELSE pg_catalog.array_to_string(%s, E'\\n')"
6894 const char *type_pattern,
bool verbose)
6899 bool have_where =
false;
6900 static const bool translate_columns[] = {
false,
false,
false,
false,
false,
false,
false};
6906 " am.amname AS \"%s\",\n"
6907 " pg_catalog.format_type(c.opcintype, NULL) AS \"%s\",\n"
6909 " WHEN c.opckeytype <> 0 AND c.opckeytype <> c.opcintype\n"
6910 " THEN pg_catalog.format_type(c.opckeytype, NULL)\n"
6914 " WHEN pg_catalog.pg_opclass_is_visible(c.oid)\n"
6915 " THEN pg_catalog.format('%%I', c.opcname)\n"
6916 " ELSE pg_catalog.format('%%I.%%I', n.nspname, c.opcname)\n"
6918 " (CASE WHEN c.opcdefault\n"
6932 " WHEN pg_catalog.pg_opfamily_is_visible(of.oid)\n"
6933 " THEN pg_catalog.format('%%I', of.opfname)\n"
6934 " ELSE pg_catalog.format('%%I.%%I', ofn.nspname, of.opfname)\n"
6936 " pg_catalog.pg_get_userbyid(c.opcowner) AS \"%s\"\n",
6940 "\nFROM pg_catalog.pg_opclass c\n"
6941 " LEFT JOIN pg_catalog.pg_am am on am.oid = c.opcmethod\n"
6942 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.opcnamespace\n"
6943 " LEFT JOIN pg_catalog.pg_type t ON t.oid = c.opcintype\n"
6944 " LEFT JOIN pg_catalog.pg_namespace tn ON tn.oid = t.typnamespace\n");
6947 " LEFT JOIN pg_catalog.pg_opfamily of ON of.oid = c.opcfamily\n"
6948 " LEFT JOIN pg_catalog.pg_namespace ofn ON ofn.oid = of.opfnamespace\n");
6950 if (access_method_pattern)
6952 false,
false, NULL,
"am.amname", NULL, NULL,
6959 "tn.nspname",
"t.typname",
6960 "pg_catalog.format_type(t.oid, NULL)",
6961 "pg_catalog.pg_type_is_visible(t.oid)",
6972 myopt.
title =
_(
"List of operator classes");
6995 const char *type_pattern,
bool verbose)
7000 bool have_where =
false;
7001 static const bool translate_columns[] = {
false,
false,
false,
false};
7007 " am.amname AS \"%s\",\n"
7009 " WHEN pg_catalog.pg_opfamily_is_visible(f.oid)\n"
7010 " THEN pg_catalog.format('%%I', f.opfname)\n"
7011 " ELSE pg_catalog.format('%%I.%%I', n.nspname, f.opfname)\n"
7014 " pg_catalog.string_agg(pg_catalog.format_type(oc.opcintype, NULL), ', ')\n"
7015 " FROM pg_catalog.pg_opclass oc\n"
7016 " WHERE oc.opcfamily = f.oid) \"%s\"",
7022 ",\n pg_catalog.pg_get_userbyid(f.opfowner) AS \"%s\"\n",
7025 "\nFROM pg_catalog.pg_opfamily f\n"
7026 " LEFT JOIN pg_catalog.pg_am am on am.oid = f.opfmethod\n"
7027 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = f.opfnamespace\n");
7029 if (access_method_pattern)
7031 false,
false, NULL,
"am.amname", NULL, NULL,
7039 " FROM pg_catalog.pg_type t\n"
7040 " JOIN pg_catalog.pg_opclass oc ON oc.opcintype = t.oid\n"
7041 " LEFT JOIN pg_catalog.pg_namespace tn ON tn.oid = t.typnamespace\n"
7042 " WHERE oc.opcfamily = f.oid\n",
7043 have_where ?
"AND" :
"WHERE");
7046 "tn.nspname",
"t.typname",
7047 "pg_catalog.format_type(t.oid, NULL)",
7048 "pg_catalog.pg_type_is_visible(t.oid)",
7060 myopt.
title =
_(
"List of operator families");
7084 const char *family_pattern,
bool verbose)
7089 bool have_where =
false;
7091 static const bool translate_columns[] = {
false,
false,
false,
false,
false,
false,
true};
7097 " am.amname AS \"%s\",\n"
7099 " WHEN pg_catalog.pg_opfamily_is_visible(of.oid)\n"
7100 " THEN pg_catalog.format('%%I', of.opfname)\n"
7101 " ELSE pg_catalog.format('%%I.%%I', nsf.nspname, of.opfname)\n"
7103 " o.amopopr::pg_catalog.regoperator AS \"%s\"\n,"
7104 " o.amopstrategy AS \"%s\",\n"
7105 " CASE o.amoppurpose\n"
7119 ", ofs.opfname AS \"%s\",\n"
7121 " WHEN p.proleakproof THEN '%s'\n"
7129 "FROM pg_catalog.pg_amop o\n"
7130 " LEFT JOIN pg_catalog.pg_opfamily of ON of.oid = o.amopfamily\n"
7131 " LEFT JOIN pg_catalog.pg_am am ON am.oid = of.opfmethod AND am.oid = o.amopmethod\n"
7132 " LEFT JOIN pg_catalog.pg_namespace nsf ON of.opfnamespace = nsf.oid\n");
7135 " LEFT JOIN pg_catalog.pg_opfamily ofs ON ofs.oid = o.amopsortfamily\n"
7136 " LEFT JOIN pg_catalog.pg_operator op ON op.oid = o.amopopr\n"
7137 " LEFT JOIN pg_catalog.pg_proc p ON p.oid = op.oprcode\n");
7139 if (access_method_pattern)
7142 false,
false, NULL,
"am.amname",
7151 "nsf.nspname",
"of.opfname", NULL, NULL,
7157 " o.amoplefttype = o.amoprighttype DESC,\n"
7158 " pg_catalog.format_type(o.amoplefttype, NULL),\n"
7159 " pg_catalog.format_type(o.amoprighttype, NULL),\n"
7160 " o.amopstrategy;");
7167 myopt.
title =
_(
"List of operators of operator families");
7191 const char *family_pattern,
bool verbose)
7196 bool have_where =
false;
7197 static const bool translate_columns[] = {
false,
false,
false,
false,
false,
false};
7203 " am.amname AS \"%s\",\n"
7205 " WHEN pg_catalog.pg_opfamily_is_visible(of.oid)\n"
7206 " THEN pg_catalog.format('%%I', of.opfname)\n"
7207 " ELSE pg_catalog.format('%%I.%%I', ns.nspname, of.opfname)\n"
7209 " pg_catalog.format_type(ap.amproclefttype, NULL) AS \"%s\",\n"
7210 " pg_catalog.format_type(ap.amprocrighttype, NULL) AS \"%s\",\n"
7211 " ap.amprocnum AS \"%s\"\n",
7220 ", p.proname AS \"%s\"\n",
7224 ", ap.amproc::pg_catalog.regprocedure AS \"%s\"\n",
7228 "FROM pg_catalog.pg_amproc ap\n"
7229 " LEFT JOIN pg_catalog.pg_opfamily of ON of.oid = ap.amprocfamily\n"
7230 " LEFT JOIN pg_catalog.pg_am am ON am.oid = of.opfmethod\n"
7231 " LEFT JOIN pg_catalog.pg_namespace ns ON of.opfnamespace = ns.oid\n"
7232 " LEFT JOIN pg_catalog.pg_proc p ON ap.amproc = p.oid\n");
7234 if (access_method_pattern)
7237 false,
false, NULL,
"am.amname",
7245 "ns.nspname",
"of.opfname", NULL, NULL,
7251 " ap.amproclefttype = ap.amprocrighttype DESC,\n"
7259 myopt.
title =
_(
"List of support functions of operator families");
7288 "SELECT oid as \"%s\",\n"
7289 " pg_catalog.pg_get_userbyid(lomowner) as \"%s\",\n ",
7300 "pg_catalog.obj_description(oid, 'pg_largeobject') as \"%s\"\n"
7301 "FROM pg_catalog.pg_largeobject_metadata\n"
7310 myopt.
title =
_(
"Large objects");
PGresult * PSQLexec(const char *query)
#define ngettext(s, p, n)
bool listUserMappings(const char *pattern, bool verbose)
bool listTSConfigs(const char *pattern, bool verbose)
bool describeRoles(const char *pattern, bool verbose, bool showSystem)
bool listOpFamilyFunctions(const char *access_method_pattern, const char *family_pattern, bool verbose)
bool listPublications(const char *pattern)
bool listTSParsers(const char *pattern, bool verbose)
bool listExtensionContents(const char *pattern)
bool describeAggregates(const char *pattern, bool verbose, bool showSystem)
bool listForeignDataWrappers(const char *pattern, bool verbose)
bool listPartitionedTables(const char *reltypes, const char *pattern, bool verbose)
bool describeSubscriptions(const char *pattern, bool verbose)
bool describeRoleGrants(const char *pattern, bool showSystem)
bool listExtendedStats(const char *pattern)
bool describeTypes(const char *pattern, bool verbose, bool showSystem)
bool listOperatorFamilies(const char *access_method_pattern, const char *type_pattern, bool verbose)
bool listForeignServers(const char *pattern, bool verbose)
bool describeTableDetails(const char *pattern, bool verbose, bool showSystem)
bool listDomains(const char *pattern, bool verbose, bool showSystem)
bool listTSDictionaries(const char *pattern, bool verbose)
bool listDbRoleSettings(const char *pattern, const char *pattern2)
bool describeFunctions(const char *functypes, const char *func_pattern, char **arg_patterns, int num_arg_patterns, bool verbose, bool showSystem)
static void add_role_attribute(PQExpBuffer buf, const char *const str)
bool listCollations(const char *pattern, bool verbose, bool showSystem)
bool listSchemas(const char *pattern, bool verbose, bool showSystem)
bool listExtensions(const char *pattern)
static bool describeOneTSConfig(const char *oid, const char *nspname, const char *cfgname, const char *pnspname, const char *prsname)
static bool listOneExtensionContents(const char *extname, const char *oid)
static bool describeOneTableDetails(const char *schemaname, const char *relationname, const char *oid, bool verbose)
static bool listTSParsersVerbose(const char *pattern)
bool listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSystem)
bool listTSTemplates(const char *pattern, bool verbose)
bool describeTablespaces(const char *pattern, bool verbose)
bool listCasts(const char *pattern, bool verbose)
bool listOpFamilyOperators(const char *access_method_pattern, const char *family_pattern, bool verbose)
bool describeOperators(const char *oper_pattern, char **arg_patterns, int num_arg_patterns, bool verbose, bool showSystem)
bool listOperatorClasses(const char *access_method_pattern, const char *type_pattern, bool verbose)
static const char * map_typename_pattern(const char *pattern)
bool listForeignTables(const char *pattern, bool verbose)
bool describeConfigurationParameters(const char *pattern, bool verbose, bool showSystem)
bool listEventTriggers(const char *pattern, bool verbose)
bool listDefaultACLs(const char *pattern)
static void printACLColumn(PQExpBuffer buf, const char *colname)
static bool addFooterToPublicationDesc(PQExpBuffer buf, const char *footermsg, bool as_schema, printTableContent *const cont)
static bool validateSQLNamePattern(PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule, bool *added_clause, int maxparts)
bool listAllDbs(const char *pattern, bool verbose)
bool listConversions(const char *pattern, bool verbose, bool showSystem)
bool permissionsList(const char *pattern, bool showSystem)
bool describeAccessMethods(const char *pattern, bool verbose)
static bool listTSConfigsVerbose(const char *pattern)
bool listLargeObjects(bool verbose)
static bool describeOneTSParser(const char *oid, const char *nspname, const char *prsname)
static void add_tablespace_footer(printTableContent *const cont, char relkind, Oid tablespace, const bool newline)
bool listLanguages(const char *pattern, bool verbose, bool showSystem)
bool describePublications(const char *pattern)
bool objectDescription(const char *pattern, bool showSystem)
char * PQdb(const PGconn *conn)
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
void PQclear(PGresult *res)
int PQntuples(const PGresult *res)
int PQfnumber(const PGresult *res, const char *field_name)
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
void * pg_malloc(size_t size)
char * pg_strdup(const char *in)
void * pg_malloc0(size_t size)
void printTableInit(printTableContent *const content, const printTableOpt *opt, const char *title, const int ncolumns, const int nrows)
void printTableCleanup(printTableContent *const content)
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
void printTableAddCell(printTableContent *const content, char *cell, const bool translate, const bool mustfree)
void printTableSetFooter(printTableContent *const content, const char *footer)
void printTable(const printTableContent *cont, FILE *fout, bool is_pager, FILE *flog)
void printTableAddFooter(printTableContent *const content, const char *footer)
void printTableAddHeader(printTableContent *const content, char *header, const bool translate, const char align)
volatile sig_atomic_t cancel_pressed
Assert(PointerIsAligned(start, uint64))
static IsoConnInfo * conns
#define pg_log_error_internal(...)
#define pg_log_error(...)
int pg_wcswidth(const char *pwcs, size_t len, int encoding)
int pg_strcasecmp(const char *s1, const char *s2)
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
void initPQExpBuffer(PQExpBuffer str)
void resetPQExpBuffer(PQExpBuffer str)
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
void appendPQExpBufferChar(PQExpBuffer str, char ch)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
void termPQExpBuffer(PQExpBuffer str)
char * psprintf(const char *fmt,...)
const char * fmtId(const char *rawid)
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule, PQExpBuffer dbnamebuf, int *dotcnt)
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
const bool * translate_columns
printTableFooter * footer
unsigned short int expanded
static StringInfoData tmpbuf