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 const char *df_options =
"anptwSx+";
300 bool showAggregate = strchr(functypes,
'a') != NULL;
301 bool showNormal = strchr(functypes,
'n') != NULL;
302 bool showProcedure = strchr(functypes,
'p') != NULL;
303 bool showTrigger = strchr(functypes,
't') != NULL;
304 bool showWindow = strchr(functypes,
'w') != NULL;
309 static const bool translate_columns[] = {
false,
false,
false,
false,
true,
true,
true,
false,
true,
true,
false,
false,
false,
false};
312 static const bool translate_columns_pre_96[] = {
false,
false,
false,
false,
true,
true,
false,
true,
true,
false,
false,
false,
false};
314 if (strlen(functypes) != strspn(functypes, df_options))
316 pg_log_error(
"\\df only takes [%s] as options", df_options);
324 pg_log_error(
"\\df does not take a \"%c\" option with server version %s",
327 sverbuf,
sizeof(sverbuf)));
331 if (!showAggregate && !showNormal && !showProcedure && !showTrigger && !showWindow)
333 showAggregate = showNormal = showTrigger = showWindow =
true;
335 showProcedure =
true;
341 "SELECT n.nspname as \"%s\",\n"
342 " p.proname as \"%s\",\n",
348 " pg_catalog.pg_get_function_result(p.oid) as \"%s\",\n"
349 " pg_catalog.pg_get_function_arguments(p.oid) as \"%s\",\n"
366 " pg_catalog.pg_get_function_result(p.oid) as \"%s\",\n"
367 " pg_catalog.pg_get_function_arguments(p.oid) as \"%s\",\n"
369 " WHEN p.proisagg THEN '%s'\n"
370 " WHEN p.proiswindow THEN '%s'\n"
371 " WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN '%s'\n"
387 " WHEN p.provolatile = "
389 " WHEN p.provolatile = "
391 " WHEN p.provolatile = "
401 " WHEN p.proparallel = "
403 " WHEN p.proparallel = "
405 " WHEN p.proparallel = "
413 ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\""
414 ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\""
415 ",\n CASE WHEN p.proleakproof THEN '%s' ELSE '%s' END as \"%s\"",
426 ",\n l.lanname as \"%s\"",
429 ",\n CASE WHEN l.lanname IN ('internal', 'c') THEN p.prosrc END as \"%s\"",
432 ",\n pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"",
437 "\nFROM pg_catalog.pg_proc p"
438 "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n");
440 for (
int i = 0;
i < num_arg_patterns;
i++)
443 " LEFT JOIN pg_catalog.pg_type t%d ON t%d.oid = p.proargtypes[%d]\n"
444 " LEFT JOIN pg_catalog.pg_namespace nt%d ON nt%d.oid = t%d.typnamespace\n",
450 " LEFT JOIN pg_catalog.pg_language l ON l.oid = p.prolang\n");
455 if (showNormal && showAggregate && showProcedure && showTrigger && showWindow)
515 bool needs_or =
false;
534 "p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype\n");
559 "n.nspname",
"p.proname", NULL,
560 "pg_catalog.pg_function_is_visible(p.oid)",
564 for (
int i = 0;
i < num_arg_patterns;
i++)
566 if (strcmp(arg_patterns[
i],
"-") != 0)
578 snprintf(nspname,
sizeof(nspname),
"nt%d.nspname",
i);
581 "pg_catalog.format_type(t%d.oid, NULL)",
i);
583 "pg_catalog.pg_type_is_visible(t%d.oid)",
i);
598 if (!showSystem && !func_pattern)
600 " AND n.nspname <> 'information_schema'\n");
609 myopt.
title =
_(
"List of functions");
648 "SELECT n.nspname as \"%s\",\n"
649 " pg_catalog.format_type(t.oid, NULL) AS \"%s\",\n",
655 " t.typname AS \"%s\",\n"
656 " CASE WHEN t.typrelid != 0\n"
657 " THEN CAST('tuple' AS pg_catalog.text)\n"
658 " WHEN t.typlen < 0\n"
659 " THEN CAST('var' AS pg_catalog.text)\n"
660 " ELSE CAST(t.typlen AS pg_catalog.text)\n"
662 " pg_catalog.array_to_string(\n"
664 " SELECT e.enumlabel\n"
665 " FROM pg_catalog.pg_enum e\n"
666 " WHERE e.enumtypid = t.oid\n"
667 " ORDER BY e.enumsortorder\n"
671 " pg_catalog.pg_get_userbyid(t.typowner) AS \"%s\",\n",
681 " pg_catalog.obj_description(t.oid, 'pg_type') as \"%s\"\n",
685 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
693 " FROM pg_catalog.pg_class c "
694 "WHERE c.oid = t.typrelid))\n");
699 if (pattern == NULL || strstr(pattern,
"[]") == NULL)
700 appendPQExpBufferStr(&
buf,
" AND NOT EXISTS(SELECT 1 FROM pg_catalog.pg_type el WHERE el.oid = t.typelem AND el.typarray = t.oid)\n");
702 if (!showSystem && !pattern)
704 " AND n.nspname <> 'information_schema'\n");
709 "n.nspname",
"t.typname",
710 "pg_catalog.format_type(t.oid, NULL)",
711 "pg_catalog.pg_type_is_visible(t.oid)",
725 myopt.
title =
_(
"List of data types");
746 static const char *
const typename_map[] = {
752 "decimal",
"numeric",
753 "float",
"double precision",
760 "bool[]",
"boolean[]",
761 "decimal[]",
"numeric[]",
762 "float[]",
"double precision[]",
763 "float4[]",
"real[]",
764 "float8[]",
"double precision[]",
765 "int[]",
"integer[]",
766 "int2[]",
"smallint[]",
767 "int4[]",
"integer[]",
768 "int8[]",
"bigint[]",
769 "time[]",
"time without time zone[]",
770 "timetz[]",
"time with time zone[]",
771 "timestamp[]",
"timestamp without time zone[]",
772 "timestamptz[]",
"timestamp with time zone[]",
773 "varbit[]",
"bit varying[]",
774 "varchar[]",
"character varying[]",
780 for (
int i = 0; typename_map[
i] != NULL;
i += 2)
783 return typename_map[
i + 1];
795 char **arg_patterns,
int num_arg_patterns,
801 static const bool translate_columns[] = {
false,
false,
false,
false,
false,
false,
true,
false};
822 "SELECT n.nspname as \"%s\",\n"
823 " o.oprname AS \"%s\",\n"
824 " CASE WHEN o.oprkind='l' THEN NULL ELSE pg_catalog.format_type(o.oprleft, NULL) END AS \"%s\",\n"
825 " CASE WHEN o.oprkind='r' THEN NULL ELSE pg_catalog.format_type(o.oprright, NULL) END AS \"%s\",\n"
826 " pg_catalog.format_type(o.oprresult, NULL) AS \"%s\",\n",
835 " o.oprcode AS \"%s\",\n"
836 " CASE WHEN p.proleakproof THEN '%s' ELSE '%s' END AS \"%s\",\n",
843 " coalesce(pg_catalog.obj_description(o.oid, 'pg_operator'),\n"
844 " pg_catalog.obj_description(o.oprcode, 'pg_proc')) AS \"%s\"\n"
845 "FROM pg_catalog.pg_operator o\n"
846 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = o.oprnamespace\n",
849 if (num_arg_patterns >= 2)
851 num_arg_patterns = 2;
853 " LEFT JOIN pg_catalog.pg_type t0 ON t0.oid = o.oprleft\n"
854 " LEFT JOIN pg_catalog.pg_namespace nt0 ON nt0.oid = t0.typnamespace\n"
855 " LEFT JOIN pg_catalog.pg_type t1 ON t1.oid = o.oprright\n"
856 " LEFT JOIN pg_catalog.pg_namespace nt1 ON nt1.oid = t1.typnamespace\n");
858 else if (num_arg_patterns == 1)
861 " LEFT JOIN pg_catalog.pg_type t0 ON t0.oid = o.oprright\n"
862 " LEFT JOIN pg_catalog.pg_namespace nt0 ON nt0.oid = t0.typnamespace\n");
867 " LEFT JOIN pg_catalog.pg_proc p ON p.oid = o.oprcode\n");
869 if (!showSystem && !oper_pattern)
871 " AND n.nspname <> 'information_schema'\n");
874 !showSystem && !oper_pattern,
true,
875 "n.nspname",
"o.oprname", NULL,
876 "pg_catalog.pg_operator_is_visible(o.oid)",
880 if (num_arg_patterns == 1)
883 for (
int i = 0;
i < num_arg_patterns;
i++)
885 if (strcmp(arg_patterns[
i],
"-") != 0)
897 snprintf(nspname,
sizeof(nspname),
"nt%d.nspname",
i);
900 "pg_catalog.format_type(t%d.oid, NULL)",
i);
902 "pg_catalog.pg_type_is_visible(t%d.oid)",
i);
924 myopt.
title =
_(
"List of operators");
956 " d.datname as \"%s\",\n"
957 " pg_catalog.pg_get_userbyid(d.datdba) as \"%s\",\n"
958 " pg_catalog.pg_encoding_to_char(d.encoding) as \"%s\",\n",
964 " CASE d.datlocprovider "
965 "WHEN " CppAsString2(COLLPROVIDER_BUILTIN)
" THEN 'builtin' "
972 " 'libc' AS \"%s\",\n",
975 " d.datcollate as \"%s\",\n"
976 " d.datctype as \"%s\",\n",
981 " d.datlocale as \"%s\",\n",
985 " d.daticulocale as \"%s\",\n",
989 " NULL as \"%s\",\n",
993 " d.daticurules as \"%s\",\n",
997 " NULL as \"%s\",\n",
1003 ",\n CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT')\n"
1004 " THEN pg_catalog.pg_size_pretty(pg_catalog.pg_database_size(d.datname))\n"
1005 " ELSE 'No Access'\n"
1007 ",\n t.spcname as \"%s\""
1008 ",\n pg_catalog.shobj_description(d.oid, 'pg_database') as \"%s\"",
1013 "\nFROM pg_catalog.pg_database d\n");
1016 " JOIN pg_catalog.pg_tablespace t on d.dattablespace = t.oid\n");
1021 NULL,
"d.datname", NULL, NULL,
1035 myopt.
title =
_(
"List of databases");
1055 static const bool translate_columns[] = {
false,
false,
true,
false,
false,
false};
1063 "SELECT n.nspname as \"%s\",\n"
1064 " c.relname as \"%s\",\n"
1070 " WHEN " CppAsString2(RELKIND_FOREIGN_TABLE)
" THEN '%s'"
1071 " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE)
" THEN '%s'"
1092 ",\n pg_catalog.array_to_string(ARRAY(\n"
1093 " SELECT attname || E':\\n ' || pg_catalog.array_to_string(attacl, E'\\n ')\n"
1094 " FROM pg_catalog.pg_attribute a\n"
1095 " WHERE attrelid = c.oid AND NOT attisdropped AND attacl IS NOT NULL\n"
1096 " ), E'\\n') AS \"%s\"",
1101 ",\n pg_catalog.array_to_string(ARRAY(\n"
1103 " || CASE WHEN polcmd != '*' THEN\n"
1104 " E' (' || polcmd::pg_catalog.text || E'):'\n"
1107 " || CASE WHEN polqual IS NOT NULL THEN\n"
1108 " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n"
1111 " || CASE WHEN polwithcheck IS NOT NULL THEN\n"
1112 " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n"
1115 " || CASE WHEN polroles <> '{0}' THEN\n"
1116 " E'\\n to: ' || pg_catalog.array_to_string(\n"
1119 " FROM pg_catalog.pg_roles\n"
1120 " WHERE oid = ANY (polroles)\n"
1125 " FROM pg_catalog.pg_policy pol\n"
1126 " WHERE polrelid = c.oid), E'\\n')\n"
1132 ",\n pg_catalog.array_to_string(ARRAY(\n"
1134 " || CASE WHEN NOT polpermissive THEN\n"
1135 " E' (RESTRICTIVE)'\n"
1137 " || CASE WHEN polcmd != '*' THEN\n"
1138 " E' (' || polcmd::pg_catalog.text || E'):'\n"
1141 " || CASE WHEN polqual IS NOT NULL THEN\n"
1142 " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n"
1145 " || CASE WHEN polwithcheck IS NOT NULL THEN\n"
1146 " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n"
1149 " || CASE WHEN polroles <> '{0}' THEN\n"
1150 " E'\\n to: ' || pg_catalog.array_to_string(\n"
1153 " FROM pg_catalog.pg_roles\n"
1154 " WHERE oid = ANY (polroles)\n"
1159 " FROM pg_catalog.pg_policy pol\n"
1160 " WHERE polrelid = c.oid), E'\\n')\n"
1165 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
1166 "WHERE c.relkind IN ("
1174 if (!showSystem && !pattern)
1176 " AND n.nspname <> 'information_schema'\n");
1179 "n.nspname",
"c.relname", NULL,
1180 "pg_catalog.pg_table_is_visible(c.oid)",
1219 static const bool translate_columns[] = {
false,
false,
true,
false};
1224 "SELECT pg_catalog.pg_get_userbyid(d.defaclrole) AS \"%s\",\n"
1225 " n.nspname AS \"%s\",\n"
1226 " CASE d.defaclobjtype "
1227 " WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' WHEN '%c' THEN '%s'"
1228 " WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' END AS \"%s\",\n"
1240 DEFACLOBJ_NAMESPACE,
1242 DEFACLOBJ_LARGEOBJECT,
1249 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.defaclnamespace\n");
1254 "pg_catalog.pg_get_userbyid(d.defaclrole)",
1300 static const bool translate_columns[] = {
false,
false,
true,
false};
1305 "SELECT DISTINCT tt.nspname AS \"%s\", tt.name AS \"%s\", tt.object AS \"%s\", d.description AS \"%s\"\n"
1314 " SELECT pgc.oid as oid, pgc.tableoid AS tableoid,\n"
1315 " n.nspname as nspname,\n"
1316 " CAST(pgc.conname AS pg_catalog.text) as name,"
1317 " CAST('%s' AS pg_catalog.text) as object\n"
1318 " FROM pg_catalog.pg_constraint pgc\n"
1319 " JOIN pg_catalog.pg_class c "
1320 "ON c.oid = pgc.conrelid\n"
1321 " LEFT JOIN pg_catalog.pg_namespace n "
1322 " ON n.oid = c.relnamespace\n",
1325 if (!showSystem && !pattern)
1327 " AND n.nspname <> 'information_schema'\n");
1330 false,
"n.nspname",
"pgc.conname", NULL,
1331 "pg_catalog.pg_table_is_visible(c.oid)",
1338 " SELECT pgc.oid as oid, pgc.tableoid AS tableoid,\n"
1339 " n.nspname as nspname,\n"
1340 " CAST(pgc.conname AS pg_catalog.text) as name,"
1341 " CAST('%s' AS pg_catalog.text) as object\n"
1342 " FROM pg_catalog.pg_constraint pgc\n"
1343 " JOIN pg_catalog.pg_type t "
1344 "ON t.oid = pgc.contypid\n"
1345 " LEFT JOIN pg_catalog.pg_namespace n "
1346 " ON n.oid = t.typnamespace\n",
1349 if (!showSystem && !pattern)
1351 " AND n.nspname <> 'information_schema'\n");
1354 false,
"n.nspname",
"pgc.conname", NULL,
1355 "pg_catalog.pg_type_is_visible(t.oid)",
1362 " SELECT o.oid as oid, o.tableoid as tableoid,\n"
1363 " n.nspname as nspname,\n"
1364 " CAST(o.opcname AS pg_catalog.text) as name,\n"
1365 " CAST('%s' AS pg_catalog.text) as object\n"
1366 " FROM pg_catalog.pg_opclass o\n"
1367 " JOIN pg_catalog.pg_am am ON "
1368 "o.opcmethod = am.oid\n"
1369 " JOIN pg_catalog.pg_namespace n ON "
1370 "n.oid = o.opcnamespace\n",
1373 if (!showSystem && !pattern)
1375 " AND n.nspname <> 'information_schema'\n");
1378 "n.nspname",
"o.opcname", NULL,
1379 "pg_catalog.pg_opclass_is_visible(o.oid)",
1386 " SELECT opf.oid as oid, opf.tableoid as tableoid,\n"
1387 " n.nspname as nspname,\n"
1388 " CAST(opf.opfname AS pg_catalog.text) AS name,\n"
1389 " CAST('%s' AS pg_catalog.text) as object\n"
1390 " FROM pg_catalog.pg_opfamily opf\n"
1391 " JOIN pg_catalog.pg_am am "
1392 "ON opf.opfmethod = am.oid\n"
1393 " JOIN pg_catalog.pg_namespace n "
1394 "ON opf.opfnamespace = n.oid\n",
1397 if (!showSystem && !pattern)
1399 " AND n.nspname <> 'information_schema'\n");
1402 "n.nspname",
"opf.opfname", NULL,
1403 "pg_catalog.pg_opfamily_is_visible(opf.oid)",
1410 " SELECT r.oid as oid, r.tableoid as tableoid,\n"
1411 " n.nspname as nspname,\n"
1412 " CAST(r.rulename AS pg_catalog.text) as name,"
1413 " CAST('%s' AS pg_catalog.text) as object\n"
1414 " FROM pg_catalog.pg_rewrite r\n"
1415 " JOIN pg_catalog.pg_class c ON c.oid = r.ev_class\n"
1416 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
1417 " WHERE r.rulename != '_RETURN'\n",
1420 if (!showSystem && !pattern)
1422 " AND n.nspname <> 'information_schema'\n");
1425 "n.nspname",
"r.rulename", NULL,
1426 "pg_catalog.pg_table_is_visible(c.oid)",
1433 " SELECT t.oid as oid, t.tableoid as tableoid,\n"
1434 " n.nspname as nspname,\n"
1435 " CAST(t.tgname AS pg_catalog.text) as name,"
1436 " CAST('%s' AS pg_catalog.text) as object\n"
1437 " FROM pg_catalog.pg_trigger t\n"
1438 " JOIN pg_catalog.pg_class c ON c.oid = t.tgrelid\n"
1439 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n",
1442 if (!showSystem && !pattern)
1444 " AND n.nspname <> 'information_schema'\n");
1447 "n.nspname",
"t.tgname", NULL,
1448 "pg_catalog.pg_table_is_visible(c.oid)",
1454 " JOIN pg_catalog.pg_description d ON (tt.oid = d.objoid AND tt.tableoid = d.classoid AND d.objsubid = 0)\n");
1463 myopt.
title =
_(
"Object descriptions");
1500 "FROM pg_catalog.pg_class c\n"
1501 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n");
1503 if (!showSystem && !pattern)
1505 " AND n.nspname <> 'information_schema'\n");
1508 "n.nspname",
"c.relname", NULL,
1509 "pg_catalog.pg_table_is_visible(c.oid)",
1528 pg_log_error(
"Did not find any relation named \"%s\".",
1540 const char *nspname;
1572 const char *relationname,
1576 bool retval =
false;
1581 bool printTableInitialized =
false;
1583 char *view_def = NULL;
1588 int attname_col = -1,
1591 attnotnull_col = -1,
1593 attidentity_col = -1,
1594 attgenerated_col = -1,
1595 isindexkey_col = -1,
1598 attstorage_col = -1,
1599 attcompression_col = -1,
1600 attstattarget_col = -1,
1611 bool forcerowsecurity;
1617 char relpersistence;
1621 bool show_column_details =
false;
1635 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1636 "c.relhastriggers, c.relrowsecurity, c.relforcerowsecurity, "
1637 "false AS relhasoids, c.relispartition, %s, c.reltablespace, "
1638 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
1639 "c.relpersistence, c.relreplident, am.amname\n"
1640 "FROM pg_catalog.pg_class c\n "
1641 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1642 "LEFT JOIN pg_catalog.pg_am am ON (c.relam = am.oid)\n"
1643 "WHERE c.oid = '%s';",
1645 "pg_catalog.array_to_string(c.reloptions || "
1646 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1653 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1654 "c.relhastriggers, c.relrowsecurity, c.relforcerowsecurity, "
1655 "c.relhasoids, c.relispartition, %s, c.reltablespace, "
1656 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
1657 "c.relpersistence, c.relreplident\n"
1658 "FROM pg_catalog.pg_class c\n "
1659 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1660 "WHERE c.oid = '%s';",
1662 "pg_catalog.array_to_string(c.reloptions || "
1663 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1670 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1671 "c.relhastriggers, c.relrowsecurity, c.relforcerowsecurity, "
1672 "c.relhasoids, false as relispartition, %s, c.reltablespace, "
1673 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
1674 "c.relpersistence, c.relreplident\n"
1675 "FROM pg_catalog.pg_class c\n "
1676 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1677 "WHERE c.oid = '%s';",
1679 "pg_catalog.array_to_string(c.reloptions || "
1680 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1687 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1688 "c.relhastriggers, false, false, c.relhasoids, "
1689 "false as relispartition, %s, c.reltablespace, "
1690 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
1691 "c.relpersistence, c.relreplident\n"
1692 "FROM pg_catalog.pg_class c\n "
1693 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1694 "WHERE c.oid = '%s';",
1696 "pg_catalog.array_to_string(c.reloptions || "
1697 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1704 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1705 "c.relhastriggers, false, false, c.relhasoids, "
1706 "false as relispartition, %s, c.reltablespace, "
1707 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
1708 "c.relpersistence\n"
1709 "FROM pg_catalog.pg_class c\n "
1710 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1711 "WHERE c.oid = '%s';",
1713 "pg_catalog.array_to_string(c.reloptions || "
1714 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1727 pg_log_error(
"Did not find any relation with OID %s.", oid);
1731 tableinfo.checks = atoi(
PQgetvalue(res, 0, 0));
1732 tableinfo.relkind = *(
PQgetvalue(res, 0, 1));
1733 tableinfo.hasindex = strcmp(
PQgetvalue(res, 0, 2),
"t") == 0;
1734 tableinfo.hasrules = strcmp(
PQgetvalue(res, 0, 3),
"t") == 0;
1735 tableinfo.hastriggers = strcmp(
PQgetvalue(res, 0, 4),
"t") == 0;
1736 tableinfo.rowsecurity = strcmp(
PQgetvalue(res, 0, 5),
"t") == 0;
1737 tableinfo.forcerowsecurity = strcmp(
PQgetvalue(res, 0, 6),
"t") == 0;
1738 tableinfo.hasoids = strcmp(
PQgetvalue(res, 0, 7),
"t") == 0;
1739 tableinfo.ispartition = strcmp(
PQgetvalue(res, 0, 8),
"t") == 0;
1742 tableinfo.reloftype = (strcmp(
PQgetvalue(res, 0, 11),
"") != 0) ?
1744 tableinfo.relpersistence = *(
PQgetvalue(res, 0, 12));
1751 tableinfo.relam = NULL;
1758 if (tableinfo.relkind == RELKIND_SEQUENCE)
1762 char *footers[3] = {NULL, NULL, NULL};
1767 "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n"
1768 " seqstart AS \"%s\",\n"
1769 " seqmin AS \"%s\",\n"
1770 " seqmax AS \"%s\",\n"
1771 " seqincrement AS \"%s\",\n"
1772 " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n"
1773 " seqcache AS \"%s\"\n",
1784 "FROM pg_catalog.pg_sequence\n"
1785 "WHERE seqrelid = '%s';",
1791 "SELECT 'bigint' AS \"%s\",\n"
1792 " start_value AS \"%s\",\n"
1793 " min_value AS \"%s\",\n"
1794 " max_value AS \"%s\",\n"
1795 " increment_by AS \"%s\",\n"
1796 " CASE WHEN is_cycled THEN '%s' ELSE '%s' END AS \"%s\",\n"
1797 " cache_value AS \"%s\"\n",
1818 "\n pg_catalog.quote_ident(relname) || '.' ||"
1819 "\n pg_catalog.quote_ident(attname),"
1821 "\nFROM pg_catalog.pg_class c"
1822 "\nINNER JOIN pg_catalog.pg_depend d ON c.oid=d.refobjid"
1823 "\nINNER JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace"
1824 "\nINNER JOIN pg_catalog.pg_attribute a ON ("
1825 "\n a.attrelid=c.oid AND"
1826 "\n a.attnum=d.refobjsubid)"
1827 "\nWHERE d.classid='pg_catalog.pg_class'::pg_catalog.regclass"
1828 "\n AND d.refclassid='pg_catalog.pg_class'::pg_catalog.regclass"
1829 "\n AND d.objid='%s'"
1830 "\n AND d.deptype IN ('a', 'i')",
1847 footers[0] =
psprintf(
_(
"Owned by: %s"),
1851 footers[0] =
psprintf(
_(
"Sequence for identity column: %s"),
1862 "\nWHERE p.puballsequences"
1863 "\n AND pg_catalog.pg_relation_is_publishable('%s')"
1875 for (
i = 0;
i < nrows;
i++)
1879 if (footers[0] == NULL)
1891 if (tableinfo.relpersistence == RELPERSISTENCE_UNLOGGED)
1893 schemaname, relationname);
1896 schemaname, relationname);
1913 if (tableinfo.relkind == RELKIND_RELATION ||
1914 tableinfo.relkind == RELKIND_VIEW ||
1915 tableinfo.relkind == RELKIND_MATVIEW ||
1916 tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
1917 tableinfo.relkind == RELKIND_COMPOSITE_TYPE ||
1918 tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
1919 show_column_details =
true;
1931 attname_col = cols++;
1933 atttype_col = cols++;
1935 if (show_column_details)
1939 ",\n (SELECT pg_catalog.pg_get_expr(d.adbin, d.adrelid, true)"
1940 "\n FROM pg_catalog.pg_attrdef d"
1941 "\n WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef)"
1942 ",\n a.attnotnull");
1943 attrdef_col = cols++;
1944 attnotnull_col = cols++;
1946 " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation");
1947 attcoll_col = cols++;
1952 attidentity_col = cols++;
1957 attgenerated_col = cols++;
1959 if (tableinfo.relkind == RELKIND_INDEX ||
1960 tableinfo.relkind == RELKIND_PARTITIONED_INDEX)
1964 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",
1968 isindexkey_col = cols++;
1971 indexdef_col = cols++;
1974 if (tableinfo.relkind == RELKIND_FOREIGN_TABLE)
1977 " '(' || pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(option_name) || ' ' || pg_catalog.quote_literal(option_value) FROM "
1978 " pg_catalog.pg_options_to_table(attfdwoptions)), ', ') || ')' END AS attfdwoptions");
1979 fdwopts_col = cols++;
1984 attstorage_col = cols++;
1989 (tableinfo.relkind == RELKIND_RELATION ||
1990 tableinfo.relkind == RELKIND_PARTITIONED_TABLE ||
1991 tableinfo.relkind == RELKIND_MATVIEW))
1994 attcompression_col = cols++;
1998 if (tableinfo.relkind == RELKIND_RELATION ||
1999 tableinfo.relkind == RELKIND_INDEX ||
2000 tableinfo.relkind == RELKIND_PARTITIONED_INDEX ||
2001 tableinfo.relkind == RELKIND_MATVIEW ||
2002 tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
2003 tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
2005 appendPQExpBufferStr(&
buf,
",\n CASE WHEN a.attstattarget=-1 THEN NULL ELSE a.attstattarget END AS attstattarget");
2006 attstattarget_col = cols++;
2013 if (tableinfo.relkind == RELKIND_RELATION ||
2014 tableinfo.relkind == RELKIND_VIEW ||
2015 tableinfo.relkind == RELKIND_MATVIEW ||
2016 tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
2017 tableinfo.relkind == RELKIND_COMPOSITE_TYPE ||
2018 tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
2021 attdescr_col = cols++;
2026 appendPQExpBuffer(&
buf,
"\nWHERE a.attrelid = '%s' AND a.attnum > 0 AND NOT a.attisdropped", oid);
2035 switch (tableinfo.relkind)
2037 case RELKIND_RELATION:
2038 if (tableinfo.relpersistence == RELPERSISTENCE_UNLOGGED)
2040 schemaname, relationname);
2043 schemaname, relationname);
2047 schemaname, relationname);
2049 case RELKIND_MATVIEW:
2051 schemaname, relationname);
2054 if (tableinfo.relpersistence == RELPERSISTENCE_UNLOGGED)
2056 schemaname, relationname);
2059 schemaname, relationname);
2061 case RELKIND_PARTITIONED_INDEX:
2062 if (tableinfo.relpersistence == RELPERSISTENCE_UNLOGGED)
2064 schemaname, relationname);
2067 schemaname, relationname);
2069 case RELKIND_TOASTVALUE:
2071 schemaname, relationname);
2073 case RELKIND_COMPOSITE_TYPE:
2075 schemaname, relationname);
2077 case RELKIND_FOREIGN_TABLE:
2079 schemaname, relationname);
2081 case RELKIND_PARTITIONED_TABLE:
2082 if (tableinfo.relpersistence == RELPERSISTENCE_UNLOGGED)
2084 schemaname, relationname);
2087 schemaname, relationname);
2092 tableinfo.relkind, schemaname, relationname);
2100 if (show_column_details)
2106 if (isindexkey_col >= 0)
2108 if (indexdef_col >= 0)
2110 if (fdwopts_col >= 0)
2112 if (attstorage_col >= 0)
2114 if (attcompression_col >= 0)
2116 if (attstattarget_col >= 0)
2118 if (attdescr_col >= 0)
2124 printTableInitialized =
true;
2126 for (
i = 0;
i < cols;
i++)
2130 for (
i = 0;
i < numrows;
i++)
2139 if (show_column_details)
2144 bool mustfree =
false;
2149 strcmp(
PQgetvalue(res,
i, attnotnull_col),
"t") == 0 ?
"not null" :
"",
2155 if (identity[0] == ATTRIBUTE_IDENTITY_ALWAYS)
2156 default_str =
"generated always as identity";
2157 else if (identity[0] == ATTRIBUTE_IDENTITY_BY_DEFAULT)
2158 default_str =
"generated by default as identity";
2159 else if (generated[0] == ATTRIBUTE_GENERATED_STORED)
2161 default_str =
psprintf(
"generated always as (%s) stored",
2165 else if (generated[0] == ATTRIBUTE_GENERATED_VIRTUAL)
2167 default_str =
psprintf(
"generated always as (%s)",
2178 if (isindexkey_col >= 0)
2180 if (indexdef_col >= 0)
2184 if (fdwopts_col >= 0)
2188 if (attstorage_col >= 0)
2194 (
storage[0] == TYPSTORAGE_MAIN ?
"main" :
2195 (
storage[0] == TYPSTORAGE_EXTENDED ?
"extended" :
2196 (
storage[0] == TYPSTORAGE_EXTERNAL ?
"external" :
2202 if (attcompression_col >= 0)
2204 char *compression =
PQgetvalue(res,
i, attcompression_col);
2208 (compression[0] ==
'l' ?
"lz4" :
2209 (compression[0] ==
'\0' ?
"" :
2215 if (attstattarget_col >= 0)
2220 if (attdescr_col >= 0)
2227 if (tableinfo.ispartition)
2233 "SELECT inhparent::pg_catalog.regclass,\n"
2234 " pg_catalog.pg_get_expr(c.relpartbound, c.oid),\n ");
2238 "false as inhdetachpending");
2243 ",\n pg_catalog.pg_get_partition_constraintdef(c.oid)");
2245 "\nFROM pg_catalog.pg_class c"
2246 " JOIN pg_catalog.pg_inherits i"
2247 " ON c.oid = inhrelid"
2248 "\nWHERE c.oid = '%s';", oid);
2255 char *parent_name =
PQgetvalue(result, 0, 0);
2261 strcmp(detached,
"t") == 0 ?
" DETACH PENDING" :
"");
2266 char *partconstraintdef = NULL;
2269 partconstraintdef =
PQgetvalue(result, 0, 3);
2271 if (partconstraintdef == NULL || partconstraintdef[0] ==
'\0')
2282 if (tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
2288 "SELECT pg_catalog.pg_get_partkeydef('%s'::pg_catalog.oid);",
2304 if (tableinfo.relkind == RELKIND_TOASTVALUE)
2310 "SELECT n.nspname, c.relname\n"
2311 "FROM pg_catalog.pg_class c"
2312 " JOIN pg_catalog.pg_namespace n"
2313 " ON n.oid = c.relnamespace\n"
2314 "WHERE reltoastrelid = '%s';", oid);
2331 if (tableinfo.relkind == RELKIND_INDEX ||
2332 tableinfo.relkind == RELKIND_PARTITIONED_INDEX)
2338 "SELECT i.indisunique, i.indisprimary, i.indisclustered, "
2340 " (NOT i.indimmediate) AND "
2341 "EXISTS (SELECT 1 FROM pg_catalog.pg_constraint "
2342 "WHERE conrelid = i.indrelid AND "
2343 "conindid = i.indexrelid AND "
2347 "condeferrable) AS condeferrable,\n"
2348 " (NOT i.indimmediate) AND "
2349 "EXISTS (SELECT 1 FROM pg_catalog.pg_constraint "
2350 "WHERE conrelid = i.indrelid AND "
2351 "conindid = i.indexrelid AND "
2355 "condeferred) AS condeferred,\n");
2368 "pg_catalog.pg_get_expr(i.indpred, i.indrelid, true)\n"
2369 "FROM pg_catalog.pg_index i, pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_am a\n"
2370 "WHERE i.indexrelid = c.oid AND c.oid = '%s' AND c.relam = a.oid\n"
2371 "AND i.indrelid = c2.oid;",
2384 char *indisunique =
PQgetvalue(result, 0, 0);
2385 char *indisprimary =
PQgetvalue(result, 0, 1);
2386 char *indisclustered =
PQgetvalue(result, 0, 2);
2390 char *indisreplident =
PQgetvalue(result, 0, 6);
2391 char *indnullsnotdistinct =
PQgetvalue(result, 0, 7);
2396 if (strcmp(indisprimary,
"t") == 0)
2398 else if (strcmp(indisunique,
"t") == 0)
2401 if (strcmp(indnullsnotdistinct,
"t") == 0)
2411 schemaname, indtable);
2413 if (strlen(indpred))
2416 if (strcmp(indisclustered,
"t") == 0)
2419 if (strcmp(indisvalid,
"t") != 0)
2422 if (strcmp(deferrable,
"t") == 0)
2425 if (strcmp(deferred,
"t") == 0)
2428 if (strcmp(indisreplident,
"t") == 0)
2436 if (tableinfo.relkind == RELKIND_INDEX)
2438 tableinfo.tablespace,
true);
2444 else if (tableinfo.relkind == RELKIND_RELATION ||
2445 tableinfo.relkind == RELKIND_MATVIEW ||
2446 tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
2447 tableinfo.relkind == RELKIND_PARTITIONED_TABLE ||
2448 tableinfo.relkind == RELKIND_PARTITIONED_INDEX ||
2449 tableinfo.relkind == RELKIND_TOASTVALUE)
2456 if (tableinfo.hasindex)
2459 "SELECT c2.relname, i.indisprimary, i.indisunique, "
2460 "i.indisclustered, i.indisvalid, "
2461 "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n "
2462 "pg_catalog.pg_get_constraintdef(con.oid, true), "
2463 "contype, condeferrable, condeferred");
2474 "\nFROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i\n"
2475 " LEFT JOIN pg_catalog.pg_constraint con ON (conrelid = i.indrelid AND conindid = i.indexrelid AND contype IN ("
2479 "WHERE c.oid = '%s' AND c.oid = i.indrelid AND i.indexrelid = c2.oid\n"
2480 "ORDER BY i.indisprimary DESC, c2.relname;",
2491 for (
i = 0;
i < tuples;
i++)
2509 const char *indexdef;
2510 const char *usingpos;
2515 else if (strcmp(
PQgetvalue(result,
i, 2),
"t") == 0)
2525 usingpos = strstr(indexdef,
" USING ");
2527 indexdef = usingpos + 7;
2560 if (tableinfo.checks)
2563 "SELECT r.conname, "
2564 "pg_catalog.pg_get_constraintdef(r.oid, true)\n"
2565 "FROM pg_catalog.pg_constraint r\n"
2566 "WHERE r.conrelid = '%s' "
2579 for (
i = 0;
i < tuples;
i++)
2594 (tableinfo.ispartition || tableinfo.relkind == RELKIND_PARTITIONED_TABLE))
2601 "SELECT conrelid = '%s'::pg_catalog.regclass AS sametable,\n"
2603 " pg_catalog.pg_get_constraintdef(oid, true) AS condef,\n"
2604 " conrelid::pg_catalog.regclass AS ontable\n"
2605 " FROM pg_catalog.pg_constraint,\n"
2606 " pg_catalog.pg_partition_ancestors('%s')\n"
2607 " WHERE conrelid = relid AND contype = " CppAsString2(CONSTRAINT_FOREIGN)
" AND conparentid = 0\n"
2608 "ORDER BY sametable DESC, conname;",
2614 "SELECT true as sametable, conname,\n"
2615 " pg_catalog.pg_get_constraintdef(r.oid, true) as condef,\n"
2616 " conrelid::pg_catalog.regclass AS ontable\n"
2617 "FROM pg_catalog.pg_constraint r\n"
2618 "WHERE r.conrelid = '%s' AND r.contype = " CppAsString2(CONSTRAINT_FOREIGN)
"\n",
2634 int i_sametable =
PQfnumber(result,
"sametable"),
2635 i_conname =
PQfnumber(result,
"conname"),
2637 i_ontable =
PQfnumber(result,
"ontable");
2640 for (
i = 0;
i < tuples;
i++)
2647 if (strcmp(
PQgetvalue(result,
i, i_sametable),
"f") == 0)
2666 "SELECT conname, conrelid::pg_catalog.regclass AS ontable,\n"
2667 " pg_catalog.pg_get_constraintdef(oid, true) AS condef\n"
2668 " FROM pg_catalog.pg_constraint c\n"
2669 " WHERE confrelid IN (SELECT pg_catalog.pg_partition_ancestors('%s')\n"
2670 " UNION ALL VALUES ('%s'::pg_catalog.regclass))\n"
2671 " AND contype = " CppAsString2(CONSTRAINT_FOREIGN)
" AND conparentid = 0\n"
2672 "ORDER BY conname;",
2678 "SELECT conname, conrelid::pg_catalog.regclass AS ontable,\n"
2679 " pg_catalog.pg_get_constraintdef(oid, true) AS condef\n"
2680 " FROM pg_catalog.pg_constraint\n"
2681 " WHERE confrelid = %s AND contype = " CppAsString2(CONSTRAINT_FOREIGN)
"\n"
2682 "ORDER BY conname;",
2694 int i_conname =
PQfnumber(result,
"conname"),
2695 i_ontable =
PQfnumber(result,
"ontable"),
2699 for (
i = 0;
i < tuples;
i++)
2717 " pol.polpermissive,\n");
2720 " 't' as polpermissive,\n");
2722 " 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"
2723 " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n"
2724 " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n"
2725 " CASE pol.polcmd\n"
2726 " WHEN 'r' THEN 'SELECT'\n"
2727 " WHEN 'a' THEN 'INSERT'\n"
2728 " WHEN 'w' THEN 'UPDATE'\n"
2729 " WHEN 'd' THEN 'DELETE'\n"
2731 "FROM pg_catalog.pg_policy pol\n"
2732 "WHERE pol.polrelid = '%s' ORDER BY 1;",
2746 if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0)
2749 if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0)
2752 if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0)
2755 if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0)
2758 if (!tableinfo.rowsecurity && tuples > 0)
2762 for (
i = 0;
i < tuples;
i++)
2798 "stxrelid::pg_catalog.regclass, "
2799 "stxnamespace::pg_catalog.regnamespace::pg_catalog.text AS nsp, "
2801 "pg_catalog.pg_get_statisticsobjdef_columns(oid) AS columns,\n"
2802 " " CppAsString2(STATS_EXT_NDISTINCT)
" = any(stxkind) AS ndist_enabled,\n"
2803 " " CppAsString2(STATS_EXT_DEPENDENCIES)
" = any(stxkind) AS deps_enabled,\n"
2804 " " CppAsString2(STATS_EXT_MCV)
" = any(stxkind) AS mcv_enabled,\n"
2806 "FROM pg_catalog.pg_statistic_ext\n"
2807 "WHERE stxrelid = '%s'\n"
2808 "ORDER BY nsp, stxname;",
2821 for (
i = 0;
i < tuples;
i++)
2823 bool gotone =
false;
2825 bool has_dependencies;
2830 has_ndistinct = (strcmp(
PQgetvalue(result,
i, 5),
"t") == 0);
2831 has_dependencies = (strcmp(
PQgetvalue(result,
i, 6),
"t") == 0);
2832 has_mcv = (strcmp(
PQgetvalue(result,
i, 7),
"t") == 0);
2849 has_all = (has_ndistinct && has_dependencies && has_mcv);
2850 has_some = (has_ndistinct || has_dependencies || has_mcv);
2852 if (has_some && !has_all)
2863 if (has_dependencies)
2896 "stxrelid::pg_catalog.regclass, "
2897 "stxnamespace::pg_catalog.regnamespace AS nsp, "
2899 " (SELECT pg_catalog.string_agg(pg_catalog.quote_ident(attname),', ')\n"
2900 " FROM pg_catalog.unnest(stxkeys) s(attnum)\n"
2901 " JOIN pg_catalog.pg_attribute a ON (stxrelid = a.attrelid AND\n"
2902 " a.attnum = s.attnum AND NOT attisdropped)) AS columns,\n"
2903 " " CppAsString2(STATS_EXT_NDISTINCT)
" = any(stxkind) AS ndist_enabled,\n"
2904 " " CppAsString2(STATS_EXT_DEPENDENCIES)
" = any(stxkind) AS deps_enabled,\n"
2905 " " CppAsString2(STATS_EXT_MCV)
" = any(stxkind) AS mcv_enabled,\n");
2912 "WHERE stxrelid = '%s'\n"
2926 for (
i = 0;
i < tuples;
i++)
2928 bool gotone =
false;
2971 if (tableinfo.hasrules && tableinfo.relkind != RELKIND_MATVIEW)
2974 "SELECT r.rulename, trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true)), "
2976 "FROM pg_catalog.pg_rewrite r\n"
2977 "WHERE r.ev_class = '%s' ORDER BY 1;",
2990 for (category = 0; category < 4; category++)
2992 have_heading =
false;
2994 for (
i = 0;
i < tuples;
i++)
2996 const char *ruledef;
2997 bool list_rule =
false;
3039 have_heading =
true;
3062 "FROM pg_catalog.pg_publication p\n"
3063 " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n"
3064 " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n"
3065 "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n"
3068 " , pg_get_expr(pr.prqual, c.oid)\n"
3069 " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n"
3070 " (SELECT string_agg(attname, ', ')\n"
3071 " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n"
3072 " pg_catalog.pg_attribute\n"
3073 " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n"
3075 "FROM pg_catalog.pg_publication p\n"
3076 " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n"
3077 " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n"
3078 "WHERE pr.prrelid = '%s'\n"
3083 "FROM pg_catalog.pg_publication p\n"
3084 "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n"
3086 oid, oid, oid, oid);
3094 "FROM pg_catalog.pg_publication p\n"
3095 "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n"
3096 "WHERE pr.prrelid = '%s'\n"
3101 "FROM pg_catalog.pg_publication p\n"
3102 "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n"
3117 for (
i = 0;
i < tuples;
i++)
3143 "SELECT c.conname, a.attname, c.connoinherit,\n"
3144 " c.conislocal, c.coninhcount <> 0,\n"
3146 "FROM pg_catalog.pg_constraint c JOIN\n"
3147 " pg_catalog.pg_attribute a ON\n"
3148 " (a.attrelid = c.conrelid AND a.attnum = c.conkey[1])\n"
3149 "WHERE c.contype = " CppAsString2(CONSTRAINT_NOTNULL)
" AND\n"
3150 " c.conrelid = '%s'::pg_catalog.regclass\n"
3151 "ORDER BY a.attnum",
3164 for (
i = 0;
i < tuples;
i++)
3166 bool islocal =
PQgetvalue(result,
i, 3)[0] ==
't';
3167 bool inherited =
PQgetvalue(result,
i, 4)[0] ==
't';
3168 bool validated =
PQgetvalue(result,
i, 5)[0] ==
't';
3175 islocal && inherited ?
_(
" (local, inherited)") :
3176 inherited ?
_(
" (inherited)") :
"",
3177 !validated ?
" NOT VALID" :
"");
3186 if ((tableinfo.relkind == RELKIND_VIEW ||
3187 tableinfo.relkind == RELKIND_MATVIEW) &&
verbose)
3192 "SELECT pg_catalog.pg_get_viewdef('%s'::pg_catalog.oid, true);",
3213 if (tableinfo.hasrules)
3216 "SELECT r.rulename, trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true))\n"
3217 "FROM pg_catalog.pg_rewrite r\n"
3218 "WHERE r.ev_class = '%s' AND r.rulename != '_RETURN' ORDER BY 1;",
3229 const char *ruledef;
3247 if (tableinfo.hastriggers)
3254 "pg_catalog.pg_get_triggerdef(t.oid, true), "
3255 "t.tgenabled, t.tgisinternal,\n");
3273 " CASE WHEN t.tgparentid != 0 THEN\n"
3274 " (SELECT u.tgrelid::pg_catalog.regclass\n"
3275 " FROM pg_catalog.pg_trigger AS u,\n"
3276 " pg_catalog.pg_partition_ancestors(t.tgrelid) WITH ORDINALITY AS a(relid, depth)\n"
3277 " WHERE u.tgname = t.tgname AND u.tgrelid = a.relid\n"
3278 " AND u.tgparentid = 0\n"
3279 " ORDER BY a.depth LIMIT 1)\n"
3280 " END AS parent\n");
3285 "FROM pg_catalog.pg_trigger t\n"
3286 "WHERE t.tgrelid = '%s' AND ",
3298 " OR EXISTS (SELECT 1 FROM pg_catalog.pg_depend WHERE objid = t.oid \n"
3299 " AND refclassid = 'pg_catalog.pg_trigger'::pg_catalog.regclass))");
3321 for (category = 0; category <= 4; category++)
3323 have_heading =
false;
3324 for (
i = 0;
i < tuples;
i++)
3328 const char *usingpos;
3329 const char *tgenabled;
3330 const char *tgisinternal;
3337 list_trigger =
false;
3341 if (*tgenabled ==
'O' || *tgenabled ==
't')
3342 list_trigger =
true;
3345 if ((*tgenabled ==
'D' || *tgenabled ==
'f') &&
3346 *tgisinternal ==
'f')
3347 list_trigger =
true;
3350 if ((*tgenabled ==
'D' || *tgenabled ==
'f') &&
3351 *tgisinternal ==
't')
3352 list_trigger =
true;
3355 if (*tgenabled ==
'A')
3356 list_trigger =
true;
3359 if (*tgenabled ==
'R')
3360 list_trigger =
true;
3363 if (list_trigger ==
false)
3367 if (have_heading ==
false)
3388 have_heading =
true;
3393 usingpos = strstr(tgdef,
" TRIGGER ");
3395 tgdef = usingpos + 9;
3414 if (tableinfo.relkind == RELKIND_RELATION ||
3415 tableinfo.relkind == RELKIND_MATVIEW ||
3416 tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
3417 tableinfo.relkind == RELKIND_PARTITIONED_TABLE ||
3418 tableinfo.relkind == RELKIND_PARTITIONED_INDEX ||
3419 tableinfo.relkind == RELKIND_TOASTVALUE)
3421 bool is_partitioned;
3426 is_partitioned = (tableinfo.relkind == RELKIND_PARTITIONED_TABLE ||
3427 tableinfo.relkind == RELKIND_PARTITIONED_INDEX);
3430 if (tableinfo.relkind == RELKIND_FOREIGN_TABLE)
3436 "SELECT s.srvname,\n"
3437 " pg_catalog.array_to_string(ARRAY(\n"
3438 " SELECT pg_catalog.quote_ident(option_name)"
3439 " || ' ' || pg_catalog.quote_literal(option_value)\n"
3440 " FROM pg_catalog.pg_options_to_table(ftoptions)), ', ')\n"
3441 "FROM pg_catalog.pg_foreign_table f,\n"
3442 " pg_catalog.pg_foreign_server s\n"
3443 "WHERE f.ftrelid = '%s' AND s.oid = f.ftserver;",
3461 if (ftoptions && ftoptions[0] !=
'\0')
3471 "SELECT c.oid::pg_catalog.regclass\n"
3472 "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n"
3473 "WHERE c.oid = i.inhparent AND i.inhrelid = '%s'\n"
3474 " AND c.relkind != " CppAsString2(RELKIND_PARTITIONED_TABLE)
3475 " AND c.relkind != " CppAsString2(RELKIND_PARTITIONED_INDEX)
3476 "\nORDER BY inhseqno;",
3484 const char *s =
_(
"Inherits");
3489 for (
i = 0;
i < tuples;
i++)
3509 "SELECT c.oid::pg_catalog.regclass, c.relkind,"
3510 " inhdetachpending,"
3511 " pg_catalog.pg_get_expr(c.relpartbound, c.oid)\n"
3512 "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n"
3513 "WHERE c.oid = i.inhrelid AND i.inhparent = '%s'\n"
3514 "ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT',"
3515 " c.oid::pg_catalog.regclass::pg_catalog.text;",
3519 "SELECT c.oid::pg_catalog.regclass, c.relkind,"
3520 " false AS inhdetachpending,"
3521 " pg_catalog.pg_get_expr(c.relpartbound, c.oid)\n"
3522 "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n"
3523 "WHERE c.oid = i.inhrelid AND i.inhparent = '%s'\n"
3524 "ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT',"
3525 " c.oid::pg_catalog.regclass::pg_catalog.text;",
3529 "SELECT c.oid::pg_catalog.regclass, c.relkind,"
3530 " false AS inhdetachpending, NULL\n"
3531 "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n"
3532 "WHERE c.oid = i.inhrelid AND i.inhparent = '%s'\n"
3533 "ORDER BY c.oid::pg_catalog.regclass::pg_catalog.text;",
3547 if (is_partitioned && tuples == 0)
3567 const char *ct = is_partitioned ?
_(
"Partitions") :
_(
"Child tables");
3570 for (
i = 0;
i < tuples;
i++)
3582 if (child_relkind == RELKIND_PARTITIONED_TABLE ||
3583 child_relkind == RELKIND_PARTITIONED_INDEX)
3585 else if (child_relkind == RELKIND_FOREIGN_TABLE)
3598 if (tableinfo.reloftype)
3605 (tableinfo.relkind == RELKIND_RELATION ||
3606 tableinfo.relkind == RELKIND_MATVIEW) &&
3612 tableinfo.relreplident != REPLICA_IDENTITY_INDEX &&
3613 ((strcmp(schemaname,
"pg_catalog") != 0 &&
3614 tableinfo.relreplident != REPLICA_IDENTITY_DEFAULT) ||
3615 (strcmp(schemaname,
"pg_catalog") == 0 &&
3616 tableinfo.relreplident != REPLICA_IDENTITY_NOTHING)))
3618 const char *s =
_(
"Replica Identity");
3622 tableinfo.relreplident == REPLICA_IDENTITY_FULL ?
"FULL" :
3623 tableinfo.relreplident == REPLICA_IDENTITY_DEFAULT ?
"NOTHING" :
3630 if (
verbose && tableinfo.relkind != RELKIND_MATVIEW && tableinfo.hasoids)
3647 tableinfo.reloptions && tableinfo.reloptions[0] !=
'\0')
3649 const char *t =
_(
"Options");
3662 if (printTableInitialized)
3685 if (relkind == RELKIND_RELATION ||
3686 relkind == RELKIND_MATVIEW ||
3687 relkind == RELKIND_INDEX ||
3688 relkind == RELKIND_PARTITIONED_TABLE ||
3689 relkind == RELKIND_PARTITIONED_INDEX ||
3690 relkind == RELKIND_TOASTVALUE)
3703 "SELECT spcname FROM pg_catalog.pg_tablespace\n"
3756 const char align =
'l';
3764 "SELECT r.rolname, r.rolsuper, r.rolinherit,\n"
3765 " r.rolcreaterole, r.rolcreatedb, r.rolcanlogin,\n"
3766 " r.rolconnlimit, r.rolvaliduntil");
3782 if (!showSystem && !pattern)
3786 NULL,
"r.rolname", NULL, NULL,
3800 attr =
pg_malloc0((nrows + 1) *
sizeof(*attr));
3810 for (
i = 0;
i < nrows;
i++)
3872 for (
i = 0;
i < nrows;
i++)
3903 "pg_catalog.array_to_string(setconfig, E'\\n') AS \"%s\"\n"
3904 "FROM pg_catalog.pg_db_role_setting s\n"
3905 "LEFT JOIN pg_catalog.pg_database d ON d.oid = setdatabase\n"
3906 "LEFT JOIN pg_catalog.pg_roles r ON r.oid = setrole\n",
3911 NULL,
"r.rolname", NULL, NULL, &havewhere, 1))
3914 NULL,
"d.datname", NULL, NULL,
3932 if (pattern && pattern2)
3933 pg_log_error(
"Did not find any settings for role \"%s\" and database \"%s\".",
3936 pg_log_error(
"Did not find any settings for role \"%s\".",
3943 myopt.
title =
_(
"List of settings");
3970 "SELECT m.rolname AS \"%s\", r.rolname AS \"%s\",\n"
3971 " pg_catalog.concat_ws(', ',\n",
3977 " CASE WHEN pam.admin_option THEN 'ADMIN' END,\n"
3978 " CASE WHEN pam.inherit_option THEN 'INHERIT' END,\n"
3979 " CASE WHEN pam.set_option THEN 'SET' END\n");
3982 " CASE WHEN pam.admin_option THEN 'ADMIN' END,\n"
3983 " CASE WHEN m.rolinherit THEN 'INHERIT' END,\n"
3988 " g.rolname AS \"%s\"\n",
3993 "FROM pg_catalog.pg_roles m\n"
3994 " JOIN pg_catalog.pg_auth_members pam ON (pam.member = m.oid)\n"
3995 " LEFT JOIN pg_catalog.pg_roles r ON (pam.roleid = r.oid)\n"
3996 " LEFT JOIN pg_catalog.pg_roles g ON (pam.grantor = g.oid)\n");
3998 if (!showSystem && !pattern)
4002 NULL,
"m.rolname", NULL, NULL,
4016 myopt.
title =
_(
"List of role grants");
4043 bool showTables = strchr(tabtypes,
't') != NULL;
4044 bool showIndexes = strchr(tabtypes,
'i') != NULL;
4045 bool showViews = strchr(tabtypes,
'v') != NULL;
4046 bool showMatViews = strchr(tabtypes,
'm') != NULL;
4047 bool showSeq = strchr(tabtypes,
's') != NULL;
4048 bool showForeign = strchr(tabtypes,
'E') != NULL;
4055 bool translate_columns[] = {
false,
false,
true,
false,
false,
false,
false,
false,
false};
4058 ntypes = showTables + showIndexes + showViews + showMatViews +
4059 showSeq + showForeign;
4062 showTables = showViews = showMatViews = showSeq = showForeign =
true;
4067 "SELECT n.nspname as \"%s\",\n"
4068 " c.relname as \"%s\",\n"
4076 " WHEN " CppAsString2(RELKIND_FOREIGN_TABLE)
" THEN '%s'"
4077 " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE)
" THEN '%s'"
4078 " WHEN " CppAsString2(RELKIND_PARTITIONED_INDEX)
" THEN '%s'"
4080 " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
4099 ",\n c2.relname as \"%s\"",
4110 ",\n CASE c.relpersistence "
4111 "WHEN " CppAsString2(RELPERSISTENCE_PERMANENT)
" THEN '%s' "
4112 "WHEN " CppAsString2(RELPERSISTENCE_TEMP)
" THEN '%s' "
4113 "WHEN " CppAsString2(RELPERSISTENCE_UNLOGGED)
" THEN '%s' "
4119 translate_columns[cols_so_far] =
true;
4131 (showTables || showMatViews || showIndexes))
4133 ",\n am.amname as \"%s\"",
4137 ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_table_size(c.oid)) as \"%s\""
4138 ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
4144 "\nFROM pg_catalog.pg_class c"
4145 "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
4148 (showTables || showMatViews || showIndexes))
4150 "\n LEFT JOIN pg_catalog.pg_am am ON am.oid = c.relam");
4154 "\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
4155 "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
4163 if (showSystem || pattern)
4175 if (showSystem || pattern)
4183 if (!showSystem && !pattern)
4185 " AND n.nspname !~ '^pg_toast'\n"
4186 " AND n.nspname <> 'information_schema'\n");
4189 "n.nspname",
"c.relname", NULL,
4190 "pg_catalog.pg_table_is_visible(c.oid)",
4214 pg_log_error(
"Did not find any relations named \"%s\".",
4216 else if (showTables)
4219 else if (showIndexes)
4225 else if (showMatViews)
4226 pg_log_error(
"Did not find any materialized views named \"%s\".",
4229 pg_log_error(
"Did not find any sequences named \"%s\".",
4231 else if (showForeign)
4232 pg_log_error(
"Did not find any foreign tables named \"%s\".",
4242 else if (showTables)
4244 else if (showIndexes)
4248 else if (showMatViews)
4252 else if (showForeign)
4261 (ntypes != 1) ?
_(
"List of relations") :
4262 (showTables) ?
_(
"List of tables") :
4263 (showIndexes) ?
_(
"List of indexes") :
4264 (showViews) ?
_(
"List of views") :
4265 (showMatViews) ?
_(
"List of materialized views") :
4266 (showSeq) ?
_(
"List of sequences") :
4267 (showForeign) ?
_(
"List of foreign tables") :
4298 bool showTables = strchr(reltypes,
't') != NULL;
4299 bool showIndexes = strchr(reltypes,
'i') != NULL;
4300 bool showNested = strchr(reltypes,
'n') != NULL;
4305 bool translate_columns[] = {
false,
false,
false,
false,
false,
false,
false,
false,
false,
false};
4306 const char *tabletitle;
4307 bool mixed_output =
false;
4316 pg_log_error(
"The server (version %s) does not support declarative table partitioning.",
4318 sverbuf,
sizeof(sverbuf)));
4323 if (!showTables && !showIndexes)
4324 showTables = showIndexes =
true;
4326 if (showIndexes && !showTables)
4327 tabletitle =
_(
"List of partitioned indexes");
4328 else if (showTables && !showIndexes)
4329 tabletitle =
_(
"List of partitioned tables");
4333 tabletitle =
_(
"List of partitioned relations");
4334 mixed_output =
true;
4340 "SELECT n.nspname as \"%s\",\n"
4341 " c.relname as \"%s\",\n"
4342 " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
4350 ",\n CASE c.relkind"
4351 " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE)
" THEN '%s'"
4352 " WHEN " CppAsString2(RELKIND_PARTITIONED_INDEX)
" THEN '%s'"
4358 translate_columns[3] =
true;
4361 if (showNested || pattern)
4363 ",\n inh.inhparent::pg_catalog.regclass as \"%s\"",
4368 ",\n c2.oid::pg_catalog.regclass as \"%s\"",
4383 ",\n s.dps as \"%s\"",
4386 ",\n s.tps as \"%s\"",
4392 ",\n s.tps as \"%s\"",
4396 ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
4401 "\nFROM pg_catalog.pg_class c"
4402 "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
4406 "\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
4407 "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
4409 if (showNested || pattern)
4411 "\n LEFT JOIN pg_catalog.pg_inherits inh ON c.oid = inh.inhrelid");
4416 "\n LEFT JOIN pg_catalog.pg_am am ON c.relam = am.oid");
4421 ",\n LATERAL (WITH RECURSIVE d\n"
4422 " AS (SELECT inhrelid AS oid, 1 AS level\n"
4423 " FROM pg_catalog.pg_inherits\n"
4424 " WHERE inhparent = c.oid\n"
4426 " SELECT inhrelid, level + 1\n"
4427 " FROM pg_catalog.pg_inherits i\n"
4428 " JOIN d ON i.inhparent = d.oid)\n"
4429 " SELECT pg_catalog.pg_size_pretty(sum(pg_catalog.pg_table_size("
4430 "d.oid))) AS tps,\n"
4431 " pg_catalog.pg_size_pretty(sum("
4432 "\n CASE WHEN d.level = 1"
4433 " THEN pg_catalog.pg_table_size(d.oid) ELSE 0 END)) AS dps\n"
4440 ",\n LATERAL (SELECT pg_catalog.pg_size_pretty(sum("
4441 "\n CASE WHEN ppt.isleaf AND ppt.level = 1"
4442 "\n THEN pg_catalog.pg_table_size(ppt.relid)"
4443 " ELSE 0 END)) AS dps"
4444 ",\n pg_catalog.pg_size_pretty(sum("
4445 "pg_catalog.pg_table_size(ppt.relid))) AS tps"
4446 "\n FROM pg_catalog.pg_partition_tree(c.oid) ppt) s");
4459 " AND NOT c.relispartition\n" :
"");
4463 " AND n.nspname !~ '^pg_toast'\n"
4464 " AND n.nspname <> 'information_schema'\n");
4467 "n.nspname",
"c.relname", NULL,
4468 "pg_catalog.pg_table_is_visible(c.oid)",
4476 mixed_output ?
"\"Type\" DESC, " :
"",
4477 showNested || pattern ?
"\"Parent name\" NULLS FIRST, " :
"");
4515 "SELECT l.lanname AS \"%s\",\n"
4516 " pg_catalog.pg_get_userbyid(l.lanowner) as \"%s\",\n"
4517 " l.lanpltrusted AS \"%s\"",
4525 ",\n NOT l.lanispl AS \"%s\",\n"
4526 " l.lanplcallfoid::pg_catalog.regprocedure AS \"%s\",\n"
4527 " l.lanvalidator::pg_catalog.regprocedure AS \"%s\",\n "
4528 "l.laninline::pg_catalog.regprocedure AS \"%s\",\n ",
4537 ",\n d.description AS \"%s\""
4538 "\nFROM pg_catalog.pg_language l\n"
4539 "LEFT JOIN pg_catalog.pg_description d\n"
4540 " ON d.classoid = l.tableoid AND d.objoid = l.oid\n"
4541 " AND d.objsubid = 0\n",
4547 NULL,
"l.lanname", NULL, NULL,
4555 if (!showSystem && !pattern)
4566 myopt.
title =
_(
"List of languages");
4591 "SELECT n.nspname as \"%s\",\n"
4592 " t.typname as \"%s\",\n"
4593 " pg_catalog.format_type(t.typbasetype, t.typtypmod) as \"%s\",\n"
4594 " (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type bt\n"
4595 " WHERE c.oid = t.typcollation AND bt.oid = t.typbasetype AND t.typcollation <> bt.typcollation) as \"%s\",\n"
4596 " CASE WHEN t.typnotnull THEN 'not null' END as \"%s\",\n"
4597 " t.typdefault as \"%s\",\n"
4598 " pg_catalog.array_to_string(ARRAY(\n"
4599 " 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"
4600 " ), ' ') as \"%s\"",
4614 ",\n d.description as \"%s\"",
4619 "\nFROM pg_catalog.pg_type t\n"
4620 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
4624 " LEFT JOIN pg_catalog.pg_description d "
4625 "ON d.classoid = t.tableoid AND d.objoid = t.oid "
4626 "AND d.objsubid = 0\n");
4630 if (!showSystem && !pattern)
4632 " AND n.nspname <> 'information_schema'\n");
4635 "n.nspname",
"t.typname", NULL,
4636 "pg_catalog.pg_type_is_visible(t.oid)",
4650 myopt.
title =
_(
"List of domains");
4670 static const bool translate_columns[] =
4671 {
false,
false,
false,
false,
true,
false};
4676 "SELECT n.nspname AS \"%s\",\n"
4677 " c.conname AS \"%s\",\n"
4678 " pg_catalog.pg_encoding_to_char(c.conforencoding) AS \"%s\",\n"
4679 " pg_catalog.pg_encoding_to_char(c.contoencoding) AS \"%s\",\n"
4680 " CASE WHEN c.condefault THEN '%s'\n"
4681 " ELSE '%s' END AS \"%s\"",
4691 ",\n d.description AS \"%s\"",
4695 "\nFROM pg_catalog.pg_conversion c\n"
4696 " JOIN pg_catalog.pg_namespace n "
4697 "ON n.oid = c.connamespace\n");
4701 "LEFT JOIN pg_catalog.pg_description d "
4702 "ON d.classoid = c.tableoid\n"
4703 " AND d.objoid = c.oid "
4704 "AND d.objsubid = 0\n");
4708 if (!showSystem && !pattern)
4710 " AND n.nspname <> 'information_schema'\n");
4713 "n.nspname",
"c.conname", NULL,
4714 "pg_catalog.pg_conversion_is_visible(c.oid)",
4728 myopt.
title =
_(
"List of conversions");
4754 "SELECT s.name AS \"%s\", "
4755 "pg_catalog.current_setting(s.name) AS \"%s\"",
4762 ", s.vartype AS \"%s\", s.context AS \"%s\", ",
4776 " LEFT JOIN pg_catalog.pg_parameter_acl p\n"
4777 " ON pg_catalog.lower(s.name) = p.parname\n");
4782 NULL,
"pg_catalog.lower(s.name)", NULL,
4786 " s.setting IS DISTINCT FROM s.boot_val\n");
4796 myopt.
title =
_(
"List of configuration parameters");
4798 myopt.
title =
_(
"List of non-default configuration parameters");
4818 static const bool translate_columns[] =
4819 {
false,
false,
false,
true,
false,
false,
false};
4825 pg_log_error(
"The server (version %s) does not support event triggers.",
4827 sverbuf,
sizeof(sverbuf)));
4834 "SELECT evtname as \"%s\", "
4835 "evtevent as \"%s\", "
4836 "pg_catalog.pg_get_userbyid(e.evtowner) as \"%s\",\n"
4837 " case evtenabled when 'O' then '%s'"
4838 " when 'R' then '%s'"
4839 " when 'A' then '%s'"
4840 " when 'D' then '%s' end as \"%s\",\n"
4841 " e.evtfoid::pg_catalog.regproc as \"%s\", "
4842 "pg_catalog.array_to_string(array(select x"
4843 " from pg_catalog.unnest(evttags) as t(x)), ', ') as \"%s\"",
4856 ",\npg_catalog.obj_description(e.oid, 'pg_event_trigger') as \"%s\"",
4859 "\nFROM pg_catalog.pg_event_trigger e ");
4862 NULL,
"evtname", NULL, NULL,
4876 myopt.
title =
_(
"List of event triggers");
4903 pg_log_error(
"The server (version %s) does not support extended statistics.",
4905 sverbuf,
sizeof(sverbuf)));
4912 "es.stxnamespace::pg_catalog.regnamespace::pg_catalog.text AS \"%s\", \n"
4913 "es.stxname AS \"%s\", \n",
4919 "pg_catalog.format('%%s FROM %%s', \n"
4920 " pg_catalog.pg_get_statisticsobjdef_columns(es.oid), \n"
4921 " es.stxrelid::pg_catalog.regclass) AS \"%s\"",
4925 "pg_catalog.format('%%s FROM %%s', \n"
4926 " (SELECT pg_catalog.string_agg(pg_catalog.quote_ident(a.attname),', ') \n"
4927 " FROM pg_catalog.unnest(es.stxkeys) s(attnum) \n"
4928 " JOIN pg_catalog.pg_attribute a \n"
4929 " ON (es.stxrelid = a.attrelid \n"
4930 " AND a.attnum = s.attnum \n"
4931 " AND NOT a.attisdropped)), \n"
4932 "es.stxrelid::pg_catalog.regclass) AS \"%s\"",
4936 ",\nCASE WHEN " CppAsString2(STATS_EXT_NDISTINCT)
" = any(es.stxkind) THEN 'defined' \n"
4938 "CASE WHEN " CppAsString2(STATS_EXT_DEPENDENCIES)
" = any(es.stxkind) THEN 'defined' \n"
4949 ",\nCASE WHEN " CppAsString2(STATS_EXT_MCV)
" = any(es.stxkind) THEN 'defined' \n"
4955 " \nFROM pg_catalog.pg_statistic_ext es \n");
4959 "es.stxnamespace::pg_catalog.regnamespace::pg_catalog.text",
"es.stxname",
4960 NULL,
"pg_catalog.pg_statistics_obj_is_visible(es.oid)",
4974 myopt.
title =
_(
"List of extended statistics");
4994 static const bool translate_columns[] = {
false,
false,
false,
true,
true,
false};
4999 "SELECT pg_catalog.format_type(castsource, NULL) AS \"%s\",\n"
5000 " pg_catalog.format_type(casttarget, NULL) AS \"%s\",\n",
5010 " CASE WHEN c.castmethod = '%c' THEN '(binary coercible)'\n"
5011 " WHEN c.castmethod = '%c' THEN '(with inout)'\n"
5013 " END AS \"%s\",\n",
5014 COERCION_METHOD_BINARY,
5015 COERCION_METHOD_INOUT,
5019 " CASE WHEN c.castcontext = '%c' THEN '%s'\n"
5020 " WHEN c.castcontext = '%c' THEN '%s'\n"
5023 COERCION_CODE_EXPLICIT,
5025 COERCION_CODE_ASSIGNMENT,
5032 ",\n CASE WHEN p.proleakproof THEN '%s'\n"
5035 " d.description AS \"%s\"",
5046 "\nFROM pg_catalog.pg_cast c LEFT JOIN pg_catalog.pg_proc p\n"
5047 " ON c.castfunc = p.oid\n"
5048 " LEFT JOIN pg_catalog.pg_type ts\n"
5049 " ON c.castsource = ts.oid\n"
5050 " LEFT JOIN pg_catalog.pg_namespace ns\n"
5051 " ON ns.oid = ts.typnamespace\n"
5052 " LEFT JOIN pg_catalog.pg_type tt\n"
5053 " ON c.casttarget = tt.oid\n"
5054 " LEFT JOIN pg_catalog.pg_namespace nt\n"
5055 " ON nt.oid = tt.typnamespace\n");
5059 " LEFT JOIN pg_catalog.pg_description d\n"
5060 " ON d.classoid = c.tableoid AND d.objoid = "
5061 "c.oid AND d.objsubid = 0\n");
5070 "ns.nspname",
"ts.typname",
5071 "pg_catalog.format_type(ts.oid, NULL)",
5072 "pg_catalog.pg_type_is_visible(ts.oid)",
5079 "nt.nspname",
"tt.typname",
5080 "pg_catalog.format_type(tt.oid, NULL)",
5081 "pg_catalog.pg_type_is_visible(tt.oid)",
5092 myopt.
title =
_(
"List of casts");
5118 static const bool translate_columns[] = {
false,
false,
false,
false,
false,
false,
false,
true,
false};
5124 " n.nspname AS \"%s\",\n"
5125 " c.collname AS \"%s\",\n",
5131 " CASE c.collprovider "
5132 "WHEN " CppAsString2(COLLPROVIDER_DEFAULT)
" THEN 'default' "
5133 "WHEN " CppAsString2(COLLPROVIDER_BUILTIN)
" THEN 'builtin' "
5134 "WHEN " CppAsString2(COLLPROVIDER_LIBC)
" THEN 'libc' "
5140 " 'libc' AS \"%s\",\n",
5144 " c.collcollate AS \"%s\",\n"
5145 " c.collctype AS \"%s\",\n",
5151 " c.colllocale AS \"%s\",\n",
5155 " c.colliculocale AS \"%s\",\n",
5159 " c.collcollate AS \"%s\",\n",
5164 " c.collicurules AS \"%s\",\n",
5168 " NULL AS \"%s\",\n",
5173 " CASE WHEN c.collisdeterministic THEN '%s' ELSE '%s' END AS \"%s\"",
5184 ",\n pg_catalog.obj_description(c.oid, 'pg_collation') AS \"%s\"",
5188 "\nFROM pg_catalog.pg_collation c, pg_catalog.pg_namespace n\n"
5189 "WHERE n.oid = c.collnamespace\n");
5191 if (!showSystem && !pattern)
5193 " AND n.nspname <> 'information_schema'\n");
5201 appendPQExpBufferStr(&
buf,
" AND c.collencoding IN (-1, pg_catalog.pg_char_to_encoding(pg_catalog.getdatabaseencoding()))\n");
5204 "n.nspname",
"c.collname", NULL,
5205 "pg_catalog.pg_collation_is_visible(c.oid)",
5219 myopt.
title =
_(
"List of collations");
5241 int pub_schema_tuples = 0;
5242 char **footers = NULL;
5246 "SELECT n.nspname AS \"%s\",\n"
5247 " pg_catalog.pg_get_userbyid(n.nspowner) AS \"%s\"",
5256 ",\n pg_catalog.obj_description(n.oid, 'pg_namespace') AS \"%s\"",
5261 "\nFROM pg_catalog.pg_namespace n\n");
5263 if (!showSystem && !pattern)
5265 "WHERE n.nspname !~ '^pg_' AND n.nspname <> 'information_schema'\n");
5268 !showSystem && !pattern,
false,
5269 NULL,
"n.nspname", NULL,
5280 myopt.
title =
_(
"List of schemas");
5290 "FROM pg_catalog.pg_publication p\n"
5291 " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n"
5292 " JOIN pg_catalog.pg_namespace n ON n.oid = pn.pnnspid \n"
5293 "WHERE n.nspname = '%s'\n"
5302 if (pub_schema_tuples > 0)
5309 footers = (
char **)
pg_malloc((1 + pub_schema_tuples + 1) *
sizeof(
char *));
5313 for (
i = 0;
i < pub_schema_tuples;
i++)
5321 footers[
i + 1] = NULL;
5336 char **footer = NULL;
5338 for (footer = footers; *footer; footer++)
5370 " n.nspname as \"%s\",\n"
5371 " p.prsname as \"%s\",\n"
5372 " pg_catalog.obj_description(p.oid, 'pg_ts_parser') as \"%s\"\n"
5373 "FROM pg_catalog.pg_ts_parser p\n"
5374 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.prsnamespace\n",
5381 "n.nspname",
"p.prsname", NULL,
5382 "pg_catalog.pg_ts_parser_is_visible(p.oid)",
5396 myopt.
title =
_(
"List of text search parsers");
5421 "FROM pg_catalog.pg_ts_parser p\n"
5422 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.prsnamespace\n"
5426 "n.nspname",
"p.prsname", NULL,
5427 "pg_catalog.pg_ts_parser_is_visible(p.oid)",
5446 pg_log_error(
"Did not find any text search parser named \"%s\".",
5458 const char *nspname = NULL;
5459 const char *prsname;
5490 static const bool translate_columns[] = {
true,
false,
false};
5495 "SELECT '%s' AS \"%s\",\n"
5496 " p.prsstart::pg_catalog.regproc AS \"%s\",\n"
5497 " pg_catalog.obj_description(p.prsstart, 'pg_proc') as \"%s\"\n"
5498 " FROM pg_catalog.pg_ts_parser p\n"
5499 " WHERE p.oid = '%s'\n"
5502 " p.prstoken::pg_catalog.regproc,\n"
5503 " pg_catalog.obj_description(p.prstoken, 'pg_proc')\n"
5504 " FROM pg_catalog.pg_ts_parser p\n"
5505 " WHERE p.oid = '%s'\n"
5508 " p.prsend::pg_catalog.regproc,\n"
5509 " pg_catalog.obj_description(p.prsend, 'pg_proc')\n"
5510 " FROM pg_catalog.pg_ts_parser p\n"
5511 " WHERE p.oid = '%s'\n"
5514 " p.prsheadline::pg_catalog.regproc,\n"
5515 " pg_catalog.obj_description(p.prsheadline, 'pg_proc')\n"
5516 " FROM pg_catalog.pg_ts_parser p\n"
5517 " WHERE p.oid = '%s'\n"
5520 " p.prslextype::pg_catalog.regproc,\n"
5521 " pg_catalog.obj_description(p.prslextype, 'pg_proc')\n"
5522 " FROM pg_catalog.pg_ts_parser p\n"
5523 " WHERE p.oid = '%s';",
5563 "SELECT t.alias as \"%s\",\n"
5564 " t.description as \"%s\"\n"
5565 "FROM pg_catalog.ts_token_type( '%s'::pg_catalog.oid ) as t\n"
5614 " n.nspname as \"%s\",\n"
5615 " d.dictname as \"%s\",\n",
5622 " ( SELECT COALESCE(nt.nspname, '(null)')::pg_catalog.text || '.' || t.tmplname FROM\n"
5623 " pg_catalog.pg_ts_template t\n"
5624 " LEFT JOIN pg_catalog.pg_namespace nt ON nt.oid = t.tmplnamespace\n"
5625 " WHERE d.dicttemplate = t.oid ) AS \"%s\",\n"
5626 " d.dictinitoption as \"%s\",\n",
5632 " pg_catalog.obj_description(d.oid, 'pg_ts_dict') as \"%s\"\n",
5636 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.dictnamespace\n");
5639 "n.nspname",
"d.dictname", NULL,
5640 "pg_catalog.pg_ts_dict_is_visible(d.oid)",
5654 myopt.
title =
_(
"List of text search dictionaries");
5680 " n.nspname AS \"%s\",\n"
5681 " t.tmplname AS \"%s\",\n"
5682 " t.tmplinit::pg_catalog.regproc AS \"%s\",\n"
5683 " t.tmpllexize::pg_catalog.regproc AS \"%s\",\n"
5684 " pg_catalog.obj_description(t.oid, 'pg_ts_template') AS \"%s\"\n",
5693 " n.nspname AS \"%s\",\n"
5694 " t.tmplname AS \"%s\",\n"
5695 " pg_catalog.obj_description(t.oid, 'pg_ts_template') AS \"%s\"\n",
5701 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.tmplnamespace\n");
5704 "n.nspname",
"t.tmplname", NULL,
5705 "pg_catalog.pg_ts_template_is_visible(t.oid)",
5719 myopt.
title =
_(
"List of text search templates");
5747 " n.nspname as \"%s\",\n"
5748 " c.cfgname as \"%s\",\n"
5749 " pg_catalog.obj_description(c.oid, 'pg_ts_config') as \"%s\"\n"
5750 "FROM pg_catalog.pg_ts_config c\n"
5751 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.cfgnamespace\n",
5758 "n.nspname",
"c.cfgname", NULL,
5759 "pg_catalog.pg_ts_config_is_visible(c.oid)",
5773 myopt.
title =
_(
"List of text search configurations");
5792 "SELECT c.oid, c.cfgname,\n"
5795 " np.nspname as pnspname\n"
5796 "FROM pg_catalog.pg_ts_config c\n"
5797 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.cfgnamespace,\n"
5798 " pg_catalog.pg_ts_parser p\n"
5799 " LEFT JOIN pg_catalog.pg_namespace np ON np.oid = p.prsnamespace\n"
5800 "WHERE p.oid = c.cfgparser\n"
5804 "n.nspname",
"c.cfgname", NULL,
5805 "pg_catalog.pg_ts_config_is_visible(c.oid)",
5824 pg_log_error(
"Did not find any text search configuration named \"%s\".",
5827 pg_log_error(
"Did not find any text search configurations.");
5836 const char *cfgname;
5837 const char *nspname = NULL;
5838 const char *prsname;
5839 const char *pnspname = NULL;
5868 const char *pnspname,
const char *prsname)
5879 " ( SELECT t.alias FROM\n"
5880 " pg_catalog.ts_token_type(c.cfgparser) AS t\n"
5881 " WHERE t.tokid = m.maptokentype ) AS \"%s\",\n"
5882 " pg_catalog.btrim(\n"
5883 " ARRAY( SELECT mm.mapdict::pg_catalog.regdictionary\n"
5884 " FROM pg_catalog.pg_ts_config_map AS mm\n"
5885 " WHERE mm.mapcfg = m.mapcfg AND mm.maptokentype = m.maptokentype\n"
5886 " ORDER BY mapcfg, maptokentype, mapseqno\n"
5887 " ) :: pg_catalog.text,\n"
5888 " '{}') AS \"%s\"\n"
5889 "FROM pg_catalog.pg_ts_config AS c, pg_catalog.pg_ts_config_map AS m\n"
5890 "WHERE c.oid = '%s' AND m.mapcfg = c.oid\n"
5891 "GROUP BY m.mapcfg, m.maptokentype, c.cfgparser\n"
5946 "SELECT fdw.fdwname AS \"%s\",\n"
5947 " pg_catalog.pg_get_userbyid(fdw.fdwowner) AS \"%s\",\n"
5948 " fdw.fdwhandler::pg_catalog.regproc AS \"%s\",\n"
5949 " fdw.fdwvalidator::pg_catalog.regproc AS \"%s\"",
5960 ",\n CASE WHEN fdwoptions IS NULL THEN '' ELSE "
5961 " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
5962 " pg_catalog.quote_ident(option_name) || ' ' || "
5963 " pg_catalog.quote_literal(option_value) FROM "
5964 " pg_catalog.pg_options_to_table(fdwoptions)), ', ') || ')' "
5966 ",\n d.description AS \"%s\" ",
5975 "LEFT JOIN pg_catalog.pg_description d\n"
5976 " ON d.classoid = fdw.tableoid "
5977 "AND d.objoid = fdw.oid AND d.objsubid = 0\n");
5980 NULL,
"fdwname", NULL, NULL,
5994 myopt.
title =
_(
"List of foreign-data wrappers");
6017 "SELECT s.srvname AS \"%s\",\n"
6018 " pg_catalog.pg_get_userbyid(s.srvowner) AS \"%s\",\n"
6019 " f.fdwname AS \"%s\"",
6030 " s.srvtype AS \"%s\",\n"
6031 " s.srvversion AS \"%s\",\n"
6032 " CASE WHEN srvoptions IS NULL THEN '' ELSE "
6033 " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
6034 " pg_catalog.quote_ident(option_name) || ' ' || "
6035 " pg_catalog.quote_literal(option_value) FROM "
6036 " pg_catalog.pg_options_to_table(srvoptions)), ', ') || ')' "
6038 " d.description AS \"%s\"",
6046 "\nFROM pg_catalog.pg_foreign_server s\n"
6047 " JOIN pg_catalog.pg_foreign_data_wrapper f ON f.oid=s.srvfdw\n");
6051 "LEFT JOIN pg_catalog.pg_description d\n "
6052 "ON d.classoid = s.tableoid AND d.objoid = s.oid "
6053 "AND d.objsubid = 0\n");
6056 NULL,
"s.srvname", NULL, NULL,
6070 myopt.
title =
_(
"List of foreign servers");
6093 "SELECT um.srvname AS \"%s\",\n"
6094 " um.usename AS \"%s\"",
6100 ",\n CASE WHEN umoptions IS NULL THEN '' ELSE "
6101 " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
6102 " pg_catalog.quote_ident(option_name) || ' ' || "
6103 " pg_catalog.quote_literal(option_value) FROM "
6104 " pg_catalog.pg_options_to_table(umoptions)), ', ') || ')' "
6111 NULL,
"um.srvname",
"um.usename", NULL,
6125 myopt.
title =
_(
"List of user mappings");
6148 "SELECT n.nspname AS \"%s\",\n"
6149 " c.relname AS \"%s\",\n"
6150 " s.srvname AS \"%s\"",
6157 ",\n CASE WHEN ftoptions IS NULL THEN '' ELSE "
6158 " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
6159 " pg_catalog.quote_ident(option_name) || ' ' || "
6160 " pg_catalog.quote_literal(option_value) FROM "
6161 " pg_catalog.pg_options_to_table(ftoptions)), ', ') || ')' "
6163 " d.description AS \"%s\"",
6168 "\nFROM pg_catalog.pg_foreign_table ft\n"
6169 " INNER JOIN pg_catalog.pg_class c"
6170 " ON c.oid = ft.ftrelid\n"
6171 " INNER JOIN pg_catalog.pg_namespace n"
6172 " ON n.oid = c.relnamespace\n"
6173 " INNER JOIN pg_catalog.pg_foreign_server s"
6174 " ON s.oid = ft.ftserver\n");
6177 " LEFT JOIN pg_catalog.pg_description d\n"
6178 " ON d.classoid = c.tableoid AND "
6179 "d.objoid = c.oid AND d.objsubid = 0\n");
6182 "n.nspname",
"c.relname", NULL,
6183 "pg_catalog.pg_table_is_visible(c.oid)",
6197 myopt.
title =
_(
"List of foreign tables");
6220 "SELECT e.extname AS \"%s\", "
6221 "e.extversion AS \"%s\", ae.default_version AS \"%s\","
6222 "n.nspname AS \"%s\", d.description AS \"%s\"\n"
6223 "FROM pg_catalog.pg_extension e "
6224 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = e.extnamespace "
6225 "LEFT JOIN pg_catalog.pg_description d ON d.objoid = e.oid "
6226 "AND d.classoid = 'pg_catalog.pg_extension'::pg_catalog.regclass "
6227 "LEFT JOIN pg_catalog.pg_available_extensions() ae(name, default_version, comment) ON ae.name = e.extname\n",
6236 NULL,
"e.extname", NULL,
6251 myopt.
title =
_(
"List of installed extensions");
6274 "SELECT e.extname, e.oid\n"
6275 "FROM pg_catalog.pg_extension e\n");
6279 NULL,
"e.extname", NULL,
6299 pg_log_error(
"Did not find any extension named \"%s\".",
6310 const char *extname;
6342 "SELECT pg_catalog.pg_describe_object(classid, objid, 0) AS \"%s\"\n"
6343 "FROM pg_catalog.pg_depend\n"
6344 "WHERE refclassid = 'pg_catalog.pg_extension'::pg_catalog.regclass AND refobjid = '%s' AND deptype = 'e'\n"
6378 bool force_escape,
const char *schemavar,
6379 const char *namevar,
const char *altnamevar,
6380 const char *visibilityrule,
bool *added_clause,
6389 schemavar, namevar, altnamevar,
6390 visibilityrule, &dbbuf, &dotcnt);
6391 if (added_clause != NULL)
6392 *added_clause = added;
6394 if (dotcnt >= maxparts)
6396 pg_log_error(
"improper qualified name (too many dotted names): %s",
6401 if (maxparts > 1 && dotcnt == maxparts - 1)
6405 pg_log_error(
"You are currently not connected to a database.");
6410 pg_log_error(
"cross-database references are not implemented: %s",
6435 static const bool translate_columns[] = {
false,
false,
false,
false,
false,
false,
false,
false,
false,
false};
6441 pg_log_error(
"The server (version %s) does not support publications.",
6443 sverbuf,
sizeof(sverbuf)));
6450 "SELECT pubname AS \"%s\",\n"
6451 " pg_catalog.pg_get_userbyid(pubowner) AS \"%s\",\n"
6452 " puballtables AS \"%s\"",
6459 ",\n puballsequences AS \"%s\"",
6463 ",\n pubinsert AS \"%s\",\n"
6464 " pubupdate AS \"%s\",\n"
6465 " pubdelete AS \"%s\"",
6471 ",\n pubtruncate AS \"%s\"",
6475 ",\n (CASE pubgencols\n"
6476 " WHEN '%c' THEN 'none'\n"
6477 " WHEN '%c' THEN 'stored'\n"
6479 PUBLISH_GENCOLS_NONE,
6480 PUBLISH_GENCOLS_STORED,
6484 ",\n pubviaroot AS \"%s\"",
6488 "\nFROM pg_catalog.pg_publication\n");
6491 NULL,
"pubname", NULL,
6506 myopt.
title =
_(
"List of publications");
6538 for (
i = 0;
i < count;
i++)
6573 bool has_pubtruncate;
6574 bool has_pubgencols;
6575 bool has_pubviaroot;
6576 bool has_pubsequence;
6585 pg_log_error(
"The server (version %s) does not support publications.",
6587 sverbuf,
sizeof(sverbuf)));
6599 "SELECT oid, pubname,\n"
6600 " pg_catalog.pg_get_userbyid(pubowner) AS owner,\n"
6603 if (has_pubsequence)
6605 ", puballsequences");
6608 ", false AS puballsequences");
6611 ", pubinsert, pubupdate, pubdelete");
6613 if (has_pubtruncate)
6618 ", false AS pubtruncate");
6622 ", (CASE pubgencols\n"
6623 " WHEN '%c' THEN 'none'\n"
6624 " WHEN '%c' THEN 'stored'\n"
6625 " END) AS \"%s\"\n",
6626 PUBLISH_GENCOLS_NONE,
6627 PUBLISH_GENCOLS_STORED,
6631 ", 'none' AS pubgencols");
6638 ", false AS pubviaroot");
6641 "\nFROM pg_catalog.pg_publication\n");
6644 NULL,
"pubname", NULL,
6666 pg_log_error(
"Did not find any publication named \"%s\".",
6679 const char align =
'l';
6684 bool puballtables = strcmp(
PQgetvalue(res,
i, 3),
"t") == 0;
6687 if (has_pubsequence)
6689 if (has_pubtruncate)
6702 if (has_pubsequence)
6707 if (has_pubtruncate)
6716 if (has_pubsequence)
6721 if (has_pubtruncate)
6732 "SELECT n.nspname, c.relname");
6736 ", pg_get_expr(pr.prqual, c.oid)");
6738 ", (CASE WHEN pr.prattrs IS NOT NULL THEN\n"
6739 " pg_catalog.array_to_string("
6740 " ARRAY(SELECT attname\n"
6742 " pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n"
6743 " pg_catalog.pg_attribute\n"
6744 " WHERE attrelid = c.oid AND attnum = prattrs[s]), ', ')\n"
6751 "\nFROM pg_catalog.pg_class c,\n"
6752 " pg_catalog.pg_namespace n,\n"
6753 " pg_catalog.pg_publication_rel pr\n"
6754 "WHERE c.relnamespace = n.oid\n"
6755 " AND c.oid = pr.prrelid\n"
6756 " AND pr.prpubid = '%s'\n"
6757 "ORDER BY 1,2", pubid);
6765 "SELECT n.nspname\n"
6766 "FROM pg_catalog.pg_namespace n\n"
6767 " JOIN pg_catalog.pg_publication_namespace pn ON n.oid = pn.pnnspid\n"
6768 "WHERE pn.pnpubid = '%s'\n"
6769 "ORDER BY 1", pubid);
6807 static const bool translate_columns[] = {
false,
false,
false,
false,
6808 false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
6809 false,
false,
false,
false};
6815 pg_log_error(
"The server (version %s) does not support subscriptions.",
6817 sverbuf,
sizeof(sverbuf)));
6824 "SELECT subname AS \"%s\"\n"
6825 ", pg_catalog.pg_get_userbyid(subowner) AS \"%s\"\n"
6826 ", subenabled AS \"%s\"\n"
6827 ", subpublications AS \"%s\"\n",
6839 ", subbinary AS \"%s\"\n",
6844 ", (CASE substream\n"
6845 " WHEN " CppAsString2(LOGICALREP_STREAM_OFF)
" THEN 'off'\n"
6846 " WHEN " CppAsString2(LOGICALREP_STREAM_ON)
" THEN 'on'\n"
6847 " WHEN " CppAsString2(LOGICALREP_STREAM_PARALLEL)
" THEN 'parallel'\n"
6848 " END) AS \"%s\"\n",
6852 ", substream AS \"%s\"\n",
6859 ", subtwophasestate AS \"%s\"\n"
6860 ", subdisableonerr AS \"%s\"\n",
6866 ", suborigin AS \"%s\"\n"
6867 ", subpasswordrequired AS \"%s\"\n"
6868 ", subrunasowner AS \"%s\"\n",
6875 ", subfailover AS \"%s\"\n",
6880 ", subretaindeadtuples AS \"%s\"\n",
6884 ", submaxretention AS \"%s\"\n",
6888 ", subretentionactive AS \"%s\"\n",
6893 ", subsynccommit AS \"%s\"\n"
6894 ", subconninfo AS \"%s\"\n",
6901 ", subskiplsn AS \"%s\"\n",
6907 "FROM pg_catalog.pg_subscription\n"
6908 "WHERE subdbid = (SELECT oid\n"
6909 " FROM pg_catalog.pg_database\n"
6910 " WHERE datname = pg_catalog.current_database())");
6913 NULL,
"subname", NULL,
6928 myopt.
title =
_(
"List of subscriptions");
6954 " WHEN pg_catalog.array_length(%s, 1) = 0 THEN '%s'"
6955 " ELSE pg_catalog.array_to_string(%s, E'\\n')"
6969 const char *type_pattern,
bool verbose)
6974 bool have_where =
false;
6975 static const bool translate_columns[] = {
false,
false,
false,
false,
false,
false,
false};
6981 " am.amname AS \"%s\",\n"
6982 " pg_catalog.format_type(c.opcintype, NULL) AS \"%s\",\n"
6984 " WHEN c.opckeytype <> 0 AND c.opckeytype <> c.opcintype\n"
6985 " THEN pg_catalog.format_type(c.opckeytype, NULL)\n"
6989 " WHEN pg_catalog.pg_opclass_is_visible(c.oid)\n"
6990 " THEN pg_catalog.format('%%I', c.opcname)\n"
6991 " ELSE pg_catalog.format('%%I.%%I', n.nspname, c.opcname)\n"
6993 " (CASE WHEN c.opcdefault\n"
7007 " WHEN pg_catalog.pg_opfamily_is_visible(of.oid)\n"
7008 " THEN pg_catalog.format('%%I', of.opfname)\n"
7009 " ELSE pg_catalog.format('%%I.%%I', ofn.nspname, of.opfname)\n"
7011 " pg_catalog.pg_get_userbyid(c.opcowner) AS \"%s\"\n",
7015 "\nFROM pg_catalog.pg_opclass c\n"
7016 " LEFT JOIN pg_catalog.pg_am am on am.oid = c.opcmethod\n"
7017 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.opcnamespace\n"
7018 " LEFT JOIN pg_catalog.pg_type t ON t.oid = c.opcintype\n"
7019 " LEFT JOIN pg_catalog.pg_namespace tn ON tn.oid = t.typnamespace\n");
7022 " LEFT JOIN pg_catalog.pg_opfamily of ON of.oid = c.opcfamily\n"
7023 " LEFT JOIN pg_catalog.pg_namespace ofn ON ofn.oid = of.opfnamespace\n");
7025 if (access_method_pattern)
7027 false,
false, NULL,
"am.amname", NULL, NULL,
7034 "tn.nspname",
"t.typname",
7035 "pg_catalog.format_type(t.oid, NULL)",
7036 "pg_catalog.pg_type_is_visible(t.oid)",
7047 myopt.
title =
_(
"List of operator classes");
7070 const char *type_pattern,
bool verbose)
7075 bool have_where =
false;
7076 static const bool translate_columns[] = {
false,
false,
false,
false};
7082 " am.amname AS \"%s\",\n"
7084 " WHEN pg_catalog.pg_opfamily_is_visible(f.oid)\n"
7085 " THEN pg_catalog.format('%%I', f.opfname)\n"
7086 " ELSE pg_catalog.format('%%I.%%I', n.nspname, f.opfname)\n"
7089 " pg_catalog.string_agg(pg_catalog.format_type(oc.opcintype, NULL), ', ')\n"
7090 " FROM pg_catalog.pg_opclass oc\n"
7091 " WHERE oc.opcfamily = f.oid) \"%s\"",
7097 ",\n pg_catalog.pg_get_userbyid(f.opfowner) AS \"%s\"\n",
7100 "\nFROM pg_catalog.pg_opfamily f\n"
7101 " LEFT JOIN pg_catalog.pg_am am on am.oid = f.opfmethod\n"
7102 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = f.opfnamespace\n");
7104 if (access_method_pattern)
7106 false,
false, NULL,
"am.amname", NULL, NULL,
7114 " FROM pg_catalog.pg_type t\n"
7115 " JOIN pg_catalog.pg_opclass oc ON oc.opcintype = t.oid\n"
7116 " LEFT JOIN pg_catalog.pg_namespace tn ON tn.oid = t.typnamespace\n"
7117 " WHERE oc.opcfamily = f.oid\n",
7118 have_where ?
"AND" :
"WHERE");
7121 "tn.nspname",
"t.typname",
7122 "pg_catalog.format_type(t.oid, NULL)",
7123 "pg_catalog.pg_type_is_visible(t.oid)",
7135 myopt.
title =
_(
"List of operator families");
7159 const char *family_pattern,
bool verbose)
7164 bool have_where =
false;
7166 static const bool translate_columns[] = {
false,
false,
false,
false,
false,
false,
true};
7172 " am.amname AS \"%s\",\n"
7174 " WHEN pg_catalog.pg_opfamily_is_visible(of.oid)\n"
7175 " THEN pg_catalog.format('%%I', of.opfname)\n"
7176 " ELSE pg_catalog.format('%%I.%%I', nsf.nspname, of.opfname)\n"
7178 " o.amopopr::pg_catalog.regoperator AS \"%s\"\n,"
7179 " o.amopstrategy AS \"%s\",\n"
7180 " CASE o.amoppurpose\n"
7194 ", ofs.opfname AS \"%s\",\n"
7196 " WHEN p.proleakproof THEN '%s'\n"
7204 "FROM pg_catalog.pg_amop o\n"
7205 " LEFT JOIN pg_catalog.pg_opfamily of ON of.oid = o.amopfamily\n"
7206 " LEFT JOIN pg_catalog.pg_am am ON am.oid = of.opfmethod AND am.oid = o.amopmethod\n"
7207 " LEFT JOIN pg_catalog.pg_namespace nsf ON of.opfnamespace = nsf.oid\n");
7210 " LEFT JOIN pg_catalog.pg_opfamily ofs ON ofs.oid = o.amopsortfamily\n"
7211 " LEFT JOIN pg_catalog.pg_operator op ON op.oid = o.amopopr\n"
7212 " LEFT JOIN pg_catalog.pg_proc p ON p.oid = op.oprcode\n");
7214 if (access_method_pattern)
7217 false,
false, NULL,
"am.amname",
7226 "nsf.nspname",
"of.opfname", NULL, NULL,
7232 " o.amoplefttype = o.amoprighttype DESC,\n"
7233 " pg_catalog.format_type(o.amoplefttype, NULL),\n"
7234 " pg_catalog.format_type(o.amoprighttype, NULL),\n"
7235 " o.amopstrategy;");
7242 myopt.
title =
_(
"List of operators of operator families");
7266 const char *family_pattern,
bool verbose)
7271 bool have_where =
false;
7272 static const bool translate_columns[] = {
false,
false,
false,
false,
false,
false};
7278 " am.amname AS \"%s\",\n"
7280 " WHEN pg_catalog.pg_opfamily_is_visible(of.oid)\n"
7281 " THEN pg_catalog.format('%%I', of.opfname)\n"
7282 " ELSE pg_catalog.format('%%I.%%I', ns.nspname, of.opfname)\n"
7284 " pg_catalog.format_type(ap.amproclefttype, NULL) AS \"%s\",\n"
7285 " pg_catalog.format_type(ap.amprocrighttype, NULL) AS \"%s\",\n"
7286 " ap.amprocnum AS \"%s\"\n",
7295 ", p.proname AS \"%s\"\n",
7299 ", ap.amproc::pg_catalog.regprocedure AS \"%s\"\n",
7303 "FROM pg_catalog.pg_amproc ap\n"
7304 " LEFT JOIN pg_catalog.pg_opfamily of ON of.oid = ap.amprocfamily\n"
7305 " LEFT JOIN pg_catalog.pg_am am ON am.oid = of.opfmethod\n"
7306 " LEFT JOIN pg_catalog.pg_namespace ns ON of.opfnamespace = ns.oid\n"
7307 " LEFT JOIN pg_catalog.pg_proc p ON ap.amproc = p.oid\n");
7309 if (access_method_pattern)
7312 false,
false, NULL,
"am.amname",
7320 "ns.nspname",
"of.opfname", NULL, NULL,
7326 " ap.amproclefttype = ap.amprocrighttype DESC,\n"
7334 myopt.
title =
_(
"List of support functions of operator families");
7363 "SELECT oid as \"%s\",\n"
7364 " pg_catalog.pg_get_userbyid(lomowner) as \"%s\",\n ",
7375 "pg_catalog.obj_description(oid, 'pg_largeobject') as \"%s\"\n"
7376 "FROM pg_catalog.pg_largeobject_metadata\n"
7385 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)
int PQfnumber(const PGresult *res, const char *field_name)
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