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[2] = {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"),
1858 if (tableinfo.relpersistence == RELPERSISTENCE_UNLOGGED)
1860 schemaname, relationname);
1863 schemaname, relationname);
1879 if (tableinfo.relkind == RELKIND_RELATION ||
1880 tableinfo.relkind == RELKIND_VIEW ||
1881 tableinfo.relkind == RELKIND_MATVIEW ||
1882 tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
1883 tableinfo.relkind == RELKIND_COMPOSITE_TYPE ||
1884 tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
1885 show_column_details =
true;
1897 attname_col = cols++;
1899 atttype_col = cols++;
1901 if (show_column_details)
1905 ",\n (SELECT pg_catalog.pg_get_expr(d.adbin, d.adrelid, true)"
1906 "\n FROM pg_catalog.pg_attrdef d"
1907 "\n WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef)"
1908 ",\n a.attnotnull");
1909 attrdef_col = cols++;
1910 attnotnull_col = cols++;
1912 " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation");
1913 attcoll_col = cols++;
1918 attidentity_col = cols++;
1923 attgenerated_col = cols++;
1925 if (tableinfo.relkind == RELKIND_INDEX ||
1926 tableinfo.relkind == RELKIND_PARTITIONED_INDEX)
1930 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",
1934 isindexkey_col = cols++;
1937 indexdef_col = cols++;
1940 if (tableinfo.relkind == RELKIND_FOREIGN_TABLE)
1943 " '(' || pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(option_name) || ' ' || pg_catalog.quote_literal(option_value) FROM "
1944 " pg_catalog.pg_options_to_table(attfdwoptions)), ', ') || ')' END AS attfdwoptions");
1945 fdwopts_col = cols++;
1950 attstorage_col = cols++;
1955 (tableinfo.relkind == RELKIND_RELATION ||
1956 tableinfo.relkind == RELKIND_PARTITIONED_TABLE ||
1957 tableinfo.relkind == RELKIND_MATVIEW))
1960 attcompression_col = cols++;
1964 if (tableinfo.relkind == RELKIND_RELATION ||
1965 tableinfo.relkind == RELKIND_INDEX ||
1966 tableinfo.relkind == RELKIND_PARTITIONED_INDEX ||
1967 tableinfo.relkind == RELKIND_MATVIEW ||
1968 tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
1969 tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
1971 appendPQExpBufferStr(&
buf,
",\n CASE WHEN a.attstattarget=-1 THEN NULL ELSE a.attstattarget END AS attstattarget");
1972 attstattarget_col = cols++;
1979 if (tableinfo.relkind == RELKIND_RELATION ||
1980 tableinfo.relkind == RELKIND_VIEW ||
1981 tableinfo.relkind == RELKIND_MATVIEW ||
1982 tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
1983 tableinfo.relkind == RELKIND_COMPOSITE_TYPE ||
1984 tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
1987 attdescr_col = cols++;
1992 appendPQExpBuffer(&
buf,
"\nWHERE a.attrelid = '%s' AND a.attnum > 0 AND NOT a.attisdropped", oid);
2001 switch (tableinfo.relkind)
2003 case RELKIND_RELATION:
2004 if (tableinfo.relpersistence == RELPERSISTENCE_UNLOGGED)
2006 schemaname, relationname);
2009 schemaname, relationname);
2013 schemaname, relationname);
2015 case RELKIND_MATVIEW:
2017 schemaname, relationname);
2020 if (tableinfo.relpersistence == RELPERSISTENCE_UNLOGGED)
2022 schemaname, relationname);
2025 schemaname, relationname);
2027 case RELKIND_PARTITIONED_INDEX:
2028 if (tableinfo.relpersistence == RELPERSISTENCE_UNLOGGED)
2030 schemaname, relationname);
2033 schemaname, relationname);
2035 case RELKIND_TOASTVALUE:
2037 schemaname, relationname);
2039 case RELKIND_COMPOSITE_TYPE:
2041 schemaname, relationname);
2043 case RELKIND_FOREIGN_TABLE:
2045 schemaname, relationname);
2047 case RELKIND_PARTITIONED_TABLE:
2048 if (tableinfo.relpersistence == RELPERSISTENCE_UNLOGGED)
2050 schemaname, relationname);
2053 schemaname, relationname);
2058 tableinfo.relkind, schemaname, relationname);
2066 if (show_column_details)
2072 if (isindexkey_col >= 0)
2074 if (indexdef_col >= 0)
2076 if (fdwopts_col >= 0)
2078 if (attstorage_col >= 0)
2080 if (attcompression_col >= 0)
2082 if (attstattarget_col >= 0)
2084 if (attdescr_col >= 0)
2090 printTableInitialized =
true;
2092 for (
i = 0;
i < cols;
i++)
2096 for (
i = 0;
i < numrows;
i++)
2105 if (show_column_details)
2110 bool mustfree =
false;
2115 strcmp(
PQgetvalue(res,
i, attnotnull_col),
"t") == 0 ?
"not null" :
"",
2121 if (identity[0] == ATTRIBUTE_IDENTITY_ALWAYS)
2122 default_str =
"generated always as identity";
2123 else if (identity[0] == ATTRIBUTE_IDENTITY_BY_DEFAULT)
2124 default_str =
"generated by default as identity";
2125 else if (generated[0] == ATTRIBUTE_GENERATED_STORED)
2127 default_str =
psprintf(
"generated always as (%s) stored",
2131 else if (generated[0] == ATTRIBUTE_GENERATED_VIRTUAL)
2133 default_str =
psprintf(
"generated always as (%s)",
2144 if (isindexkey_col >= 0)
2146 if (indexdef_col >= 0)
2150 if (fdwopts_col >= 0)
2154 if (attstorage_col >= 0)
2160 (
storage[0] == TYPSTORAGE_MAIN ?
"main" :
2161 (
storage[0] == TYPSTORAGE_EXTENDED ?
"extended" :
2162 (
storage[0] == TYPSTORAGE_EXTERNAL ?
"external" :
2168 if (attcompression_col >= 0)
2170 char *compression =
PQgetvalue(res,
i, attcompression_col);
2174 (compression[0] ==
'l' ?
"lz4" :
2175 (compression[0] ==
'\0' ?
"" :
2181 if (attstattarget_col >= 0)
2186 if (attdescr_col >= 0)
2193 if (tableinfo.ispartition)
2199 "SELECT inhparent::pg_catalog.regclass,\n"
2200 " pg_catalog.pg_get_expr(c.relpartbound, c.oid),\n ");
2204 "false as inhdetachpending");
2209 ",\n pg_catalog.pg_get_partition_constraintdef(c.oid)");
2211 "\nFROM pg_catalog.pg_class c"
2212 " JOIN pg_catalog.pg_inherits i"
2213 " ON c.oid = inhrelid"
2214 "\nWHERE c.oid = '%s';", oid);
2221 char *parent_name =
PQgetvalue(result, 0, 0);
2227 strcmp(detached,
"t") == 0 ?
" DETACH PENDING" :
"");
2232 char *partconstraintdef = NULL;
2235 partconstraintdef =
PQgetvalue(result, 0, 3);
2237 if (partconstraintdef == NULL || partconstraintdef[0] ==
'\0')
2248 if (tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
2254 "SELECT pg_catalog.pg_get_partkeydef('%s'::pg_catalog.oid);",
2270 if (tableinfo.relkind == RELKIND_TOASTVALUE)
2276 "SELECT n.nspname, c.relname\n"
2277 "FROM pg_catalog.pg_class c"
2278 " JOIN pg_catalog.pg_namespace n"
2279 " ON n.oid = c.relnamespace\n"
2280 "WHERE reltoastrelid = '%s';", oid);
2297 if (tableinfo.relkind == RELKIND_INDEX ||
2298 tableinfo.relkind == RELKIND_PARTITIONED_INDEX)
2304 "SELECT i.indisunique, i.indisprimary, i.indisclustered, "
2306 " (NOT i.indimmediate) AND "
2307 "EXISTS (SELECT 1 FROM pg_catalog.pg_constraint "
2308 "WHERE conrelid = i.indrelid AND "
2309 "conindid = i.indexrelid AND "
2313 "condeferrable) AS condeferrable,\n"
2314 " (NOT i.indimmediate) AND "
2315 "EXISTS (SELECT 1 FROM pg_catalog.pg_constraint "
2316 "WHERE conrelid = i.indrelid AND "
2317 "conindid = i.indexrelid AND "
2321 "condeferred) AS condeferred,\n");
2334 "pg_catalog.pg_get_expr(i.indpred, i.indrelid, true)\n"
2335 "FROM pg_catalog.pg_index i, pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_am a\n"
2336 "WHERE i.indexrelid = c.oid AND c.oid = '%s' AND c.relam = a.oid\n"
2337 "AND i.indrelid = c2.oid;",
2350 char *indisunique =
PQgetvalue(result, 0, 0);
2351 char *indisprimary =
PQgetvalue(result, 0, 1);
2352 char *indisclustered =
PQgetvalue(result, 0, 2);
2356 char *indisreplident =
PQgetvalue(result, 0, 6);
2357 char *indnullsnotdistinct =
PQgetvalue(result, 0, 7);
2362 if (strcmp(indisprimary,
"t") == 0)
2364 else if (strcmp(indisunique,
"t") == 0)
2367 if (strcmp(indnullsnotdistinct,
"t") == 0)
2377 schemaname, indtable);
2379 if (strlen(indpred))
2382 if (strcmp(indisclustered,
"t") == 0)
2385 if (strcmp(indisvalid,
"t") != 0)
2388 if (strcmp(deferrable,
"t") == 0)
2391 if (strcmp(deferred,
"t") == 0)
2394 if (strcmp(indisreplident,
"t") == 0)
2402 if (tableinfo.relkind == RELKIND_INDEX)
2404 tableinfo.tablespace,
true);
2410 else if (tableinfo.relkind == RELKIND_RELATION ||
2411 tableinfo.relkind == RELKIND_MATVIEW ||
2412 tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
2413 tableinfo.relkind == RELKIND_PARTITIONED_TABLE ||
2414 tableinfo.relkind == RELKIND_PARTITIONED_INDEX ||
2415 tableinfo.relkind == RELKIND_TOASTVALUE)
2422 if (tableinfo.hasindex)
2425 "SELECT c2.relname, i.indisprimary, i.indisunique, "
2426 "i.indisclustered, i.indisvalid, "
2427 "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n "
2428 "pg_catalog.pg_get_constraintdef(con.oid, true), "
2429 "contype, condeferrable, condeferred");
2440 "\nFROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i\n"
2441 " LEFT JOIN pg_catalog.pg_constraint con ON (conrelid = i.indrelid AND conindid = i.indexrelid AND contype IN ("
2445 "WHERE c.oid = '%s' AND c.oid = i.indrelid AND i.indexrelid = c2.oid\n"
2446 "ORDER BY i.indisprimary DESC, c2.relname;",
2457 for (
i = 0;
i < tuples;
i++)
2475 const char *indexdef;
2476 const char *usingpos;
2481 else if (strcmp(
PQgetvalue(result,
i, 2),
"t") == 0)
2491 usingpos = strstr(indexdef,
" USING ");
2493 indexdef = usingpos + 7;
2526 if (tableinfo.checks)
2529 "SELECT r.conname, "
2530 "pg_catalog.pg_get_constraintdef(r.oid, true)\n"
2531 "FROM pg_catalog.pg_constraint r\n"
2532 "WHERE r.conrelid = '%s' "
2545 for (
i = 0;
i < tuples;
i++)
2560 (tableinfo.ispartition || tableinfo.relkind == RELKIND_PARTITIONED_TABLE))
2567 "SELECT conrelid = '%s'::pg_catalog.regclass AS sametable,\n"
2569 " pg_catalog.pg_get_constraintdef(oid, true) AS condef,\n"
2570 " conrelid::pg_catalog.regclass AS ontable\n"
2571 " FROM pg_catalog.pg_constraint,\n"
2572 " pg_catalog.pg_partition_ancestors('%s')\n"
2573 " WHERE conrelid = relid AND contype = " CppAsString2(CONSTRAINT_FOREIGN)
" AND conparentid = 0\n"
2574 "ORDER BY sametable DESC, conname;",
2580 "SELECT true as sametable, conname,\n"
2581 " pg_catalog.pg_get_constraintdef(r.oid, true) as condef,\n"
2582 " conrelid::pg_catalog.regclass AS ontable\n"
2583 "FROM pg_catalog.pg_constraint r\n"
2584 "WHERE r.conrelid = '%s' AND r.contype = " CppAsString2(CONSTRAINT_FOREIGN)
"\n",
2600 int i_sametable =
PQfnumber(result,
"sametable"),
2601 i_conname =
PQfnumber(result,
"conname"),
2603 i_ontable =
PQfnumber(result,
"ontable");
2606 for (
i = 0;
i < tuples;
i++)
2613 if (strcmp(
PQgetvalue(result,
i, i_sametable),
"f") == 0)
2632 "SELECT conname, conrelid::pg_catalog.regclass AS ontable,\n"
2633 " pg_catalog.pg_get_constraintdef(oid, true) AS condef\n"
2634 " FROM pg_catalog.pg_constraint c\n"
2635 " WHERE confrelid IN (SELECT pg_catalog.pg_partition_ancestors('%s')\n"
2636 " UNION ALL VALUES ('%s'::pg_catalog.regclass))\n"
2637 " AND contype = " CppAsString2(CONSTRAINT_FOREIGN)
" AND conparentid = 0\n"
2638 "ORDER BY conname;",
2644 "SELECT conname, conrelid::pg_catalog.regclass AS ontable,\n"
2645 " pg_catalog.pg_get_constraintdef(oid, true) AS condef\n"
2646 " FROM pg_catalog.pg_constraint\n"
2647 " WHERE confrelid = %s AND contype = " CppAsString2(CONSTRAINT_FOREIGN)
"\n"
2648 "ORDER BY conname;",
2660 int i_conname =
PQfnumber(result,
"conname"),
2661 i_ontable =
PQfnumber(result,
"ontable"),
2665 for (
i = 0;
i < tuples;
i++)
2683 " pol.polpermissive,\n");
2686 " 't' as polpermissive,\n");
2688 " 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"
2689 " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n"
2690 " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n"
2691 " CASE pol.polcmd\n"
2692 " WHEN 'r' THEN 'SELECT'\n"
2693 " WHEN 'a' THEN 'INSERT'\n"
2694 " WHEN 'w' THEN 'UPDATE'\n"
2695 " WHEN 'd' THEN 'DELETE'\n"
2697 "FROM pg_catalog.pg_policy pol\n"
2698 "WHERE pol.polrelid = '%s' ORDER BY 1;",
2712 if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0)
2715 if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0)
2718 if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0)
2721 if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0)
2724 if (!tableinfo.rowsecurity && tuples > 0)
2728 for (
i = 0;
i < tuples;
i++)
2764 "stxrelid::pg_catalog.regclass, "
2765 "stxnamespace::pg_catalog.regnamespace::pg_catalog.text AS nsp, "
2767 "pg_catalog.pg_get_statisticsobjdef_columns(oid) AS columns,\n"
2768 " " CppAsString2(STATS_EXT_NDISTINCT)
" = any(stxkind) AS ndist_enabled,\n"
2769 " " CppAsString2(STATS_EXT_DEPENDENCIES)
" = any(stxkind) AS deps_enabled,\n"
2770 " " CppAsString2(STATS_EXT_MCV)
" = any(stxkind) AS mcv_enabled,\n"
2772 "FROM pg_catalog.pg_statistic_ext\n"
2773 "WHERE stxrelid = '%s'\n"
2774 "ORDER BY nsp, stxname;",
2787 for (
i = 0;
i < tuples;
i++)
2789 bool gotone =
false;
2791 bool has_dependencies;
2796 has_ndistinct = (strcmp(
PQgetvalue(result,
i, 5),
"t") == 0);
2797 has_dependencies = (strcmp(
PQgetvalue(result,
i, 6),
"t") == 0);
2798 has_mcv = (strcmp(
PQgetvalue(result,
i, 7),
"t") == 0);
2815 has_all = (has_ndistinct && has_dependencies && has_mcv);
2816 has_some = (has_ndistinct || has_dependencies || has_mcv);
2818 if (has_some && !has_all)
2829 if (has_dependencies)
2862 "stxrelid::pg_catalog.regclass, "
2863 "stxnamespace::pg_catalog.regnamespace AS nsp, "
2865 " (SELECT pg_catalog.string_agg(pg_catalog.quote_ident(attname),', ')\n"
2866 " FROM pg_catalog.unnest(stxkeys) s(attnum)\n"
2867 " JOIN pg_catalog.pg_attribute a ON (stxrelid = a.attrelid AND\n"
2868 " a.attnum = s.attnum AND NOT attisdropped)) AS columns,\n"
2869 " " CppAsString2(STATS_EXT_NDISTINCT)
" = any(stxkind) AS ndist_enabled,\n"
2870 " " CppAsString2(STATS_EXT_DEPENDENCIES)
" = any(stxkind) AS deps_enabled,\n"
2871 " " CppAsString2(STATS_EXT_MCV)
" = any(stxkind) AS mcv_enabled,\n");
2878 "WHERE stxrelid = '%s'\n"
2892 for (
i = 0;
i < tuples;
i++)
2894 bool gotone =
false;
2937 if (tableinfo.hasrules && tableinfo.relkind != RELKIND_MATVIEW)
2940 "SELECT r.rulename, trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true)), "
2942 "FROM pg_catalog.pg_rewrite r\n"
2943 "WHERE r.ev_class = '%s' ORDER BY 1;",
2956 for (category = 0; category < 4; category++)
2958 have_heading =
false;
2960 for (
i = 0;
i < tuples;
i++)
2962 const char *ruledef;
2963 bool list_rule =
false;
3005 have_heading =
true;
3028 "FROM pg_catalog.pg_publication p\n"
3029 " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n"
3030 " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n"
3031 "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n"
3034 " , pg_get_expr(pr.prqual, c.oid)\n"
3035 " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n"
3036 " (SELECT string_agg(attname, ', ')\n"
3037 " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n"
3038 " pg_catalog.pg_attribute\n"
3039 " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n"
3041 "FROM pg_catalog.pg_publication p\n"
3042 " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n"
3043 " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n"
3044 "WHERE pr.prrelid = '%s'\n"
3049 "FROM pg_catalog.pg_publication p\n"
3050 "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n"
3052 oid, oid, oid, oid);
3060 "FROM pg_catalog.pg_publication p\n"
3061 "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n"
3062 "WHERE pr.prrelid = '%s'\n"
3067 "FROM pg_catalog.pg_publication p\n"
3068 "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n"
3083 for (
i = 0;
i < tuples;
i++)
3109 "SELECT c.conname, a.attname, c.connoinherit,\n"
3110 " c.conislocal, c.coninhcount <> 0,\n"
3112 "FROM pg_catalog.pg_constraint c JOIN\n"
3113 " pg_catalog.pg_attribute a ON\n"
3114 " (a.attrelid = c.conrelid AND a.attnum = c.conkey[1])\n"
3115 "WHERE c.contype = " CppAsString2(CONSTRAINT_NOTNULL)
" AND\n"
3116 " c.conrelid = '%s'::pg_catalog.regclass\n"
3117 "ORDER BY a.attnum",
3130 for (
i = 0;
i < tuples;
i++)
3132 bool islocal =
PQgetvalue(result,
i, 3)[0] ==
't';
3133 bool inherited =
PQgetvalue(result,
i, 4)[0] ==
't';
3134 bool validated =
PQgetvalue(result,
i, 5)[0] ==
't';
3141 islocal && inherited ?
_(
" (local, inherited)") :
3142 inherited ?
_(
" (inherited)") :
"",
3143 !validated ?
" NOT VALID" :
"");
3152 if ((tableinfo.relkind == RELKIND_VIEW ||
3153 tableinfo.relkind == RELKIND_MATVIEW) &&
verbose)
3158 "SELECT pg_catalog.pg_get_viewdef('%s'::pg_catalog.oid, true);",
3179 if (tableinfo.hasrules)
3182 "SELECT r.rulename, trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true))\n"
3183 "FROM pg_catalog.pg_rewrite r\n"
3184 "WHERE r.ev_class = '%s' AND r.rulename != '_RETURN' ORDER BY 1;",
3195 const char *ruledef;
3213 if (tableinfo.hastriggers)
3220 "pg_catalog.pg_get_triggerdef(t.oid, true), "
3221 "t.tgenabled, t.tgisinternal,\n");
3239 " CASE WHEN t.tgparentid != 0 THEN\n"
3240 " (SELECT u.tgrelid::pg_catalog.regclass\n"
3241 " FROM pg_catalog.pg_trigger AS u,\n"
3242 " pg_catalog.pg_partition_ancestors(t.tgrelid) WITH ORDINALITY AS a(relid, depth)\n"
3243 " WHERE u.tgname = t.tgname AND u.tgrelid = a.relid\n"
3244 " AND u.tgparentid = 0\n"
3245 " ORDER BY a.depth LIMIT 1)\n"
3246 " END AS parent\n");
3251 "FROM pg_catalog.pg_trigger t\n"
3252 "WHERE t.tgrelid = '%s' AND ",
3264 " OR EXISTS (SELECT 1 FROM pg_catalog.pg_depend WHERE objid = t.oid \n"
3265 " AND refclassid = 'pg_catalog.pg_trigger'::pg_catalog.regclass))");
3287 for (category = 0; category <= 4; category++)
3289 have_heading =
false;
3290 for (
i = 0;
i < tuples;
i++)
3294 const char *usingpos;
3295 const char *tgenabled;
3296 const char *tgisinternal;
3303 list_trigger =
false;
3307 if (*tgenabled ==
'O' || *tgenabled ==
't')
3308 list_trigger =
true;
3311 if ((*tgenabled ==
'D' || *tgenabled ==
'f') &&
3312 *tgisinternal ==
'f')
3313 list_trigger =
true;
3316 if ((*tgenabled ==
'D' || *tgenabled ==
'f') &&
3317 *tgisinternal ==
't')
3318 list_trigger =
true;
3321 if (*tgenabled ==
'A')
3322 list_trigger =
true;
3325 if (*tgenabled ==
'R')
3326 list_trigger =
true;
3329 if (list_trigger ==
false)
3333 if (have_heading ==
false)
3354 have_heading =
true;
3359 usingpos = strstr(tgdef,
" TRIGGER ");
3361 tgdef = usingpos + 9;
3380 if (tableinfo.relkind == RELKIND_RELATION ||
3381 tableinfo.relkind == RELKIND_MATVIEW ||
3382 tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
3383 tableinfo.relkind == RELKIND_PARTITIONED_TABLE ||
3384 tableinfo.relkind == RELKIND_PARTITIONED_INDEX ||
3385 tableinfo.relkind == RELKIND_TOASTVALUE)
3387 bool is_partitioned;
3392 is_partitioned = (tableinfo.relkind == RELKIND_PARTITIONED_TABLE ||
3393 tableinfo.relkind == RELKIND_PARTITIONED_INDEX);
3396 if (tableinfo.relkind == RELKIND_FOREIGN_TABLE)
3402 "SELECT s.srvname,\n"
3403 " pg_catalog.array_to_string(ARRAY(\n"
3404 " SELECT pg_catalog.quote_ident(option_name)"
3405 " || ' ' || pg_catalog.quote_literal(option_value)\n"
3406 " FROM pg_catalog.pg_options_to_table(ftoptions)), ', ')\n"
3407 "FROM pg_catalog.pg_foreign_table f,\n"
3408 " pg_catalog.pg_foreign_server s\n"
3409 "WHERE f.ftrelid = '%s' AND s.oid = f.ftserver;",
3427 if (ftoptions && ftoptions[0] !=
'\0')
3437 "SELECT c.oid::pg_catalog.regclass\n"
3438 "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n"
3439 "WHERE c.oid = i.inhparent AND i.inhrelid = '%s'\n"
3440 " AND c.relkind != " CppAsString2(RELKIND_PARTITIONED_TABLE)
3441 " AND c.relkind != " CppAsString2(RELKIND_PARTITIONED_INDEX)
3442 "\nORDER BY inhseqno;",
3450 const char *s =
_(
"Inherits");
3455 for (
i = 0;
i < tuples;
i++)
3475 "SELECT c.oid::pg_catalog.regclass, c.relkind,"
3476 " inhdetachpending,"
3477 " pg_catalog.pg_get_expr(c.relpartbound, c.oid)\n"
3478 "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n"
3479 "WHERE c.oid = i.inhrelid AND i.inhparent = '%s'\n"
3480 "ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT',"
3481 " c.oid::pg_catalog.regclass::pg_catalog.text;",
3485 "SELECT c.oid::pg_catalog.regclass, c.relkind,"
3486 " false AS inhdetachpending,"
3487 " pg_catalog.pg_get_expr(c.relpartbound, c.oid)\n"
3488 "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n"
3489 "WHERE c.oid = i.inhrelid AND i.inhparent = '%s'\n"
3490 "ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT',"
3491 " c.oid::pg_catalog.regclass::pg_catalog.text;",
3495 "SELECT c.oid::pg_catalog.regclass, c.relkind,"
3496 " false AS inhdetachpending, NULL\n"
3497 "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n"
3498 "WHERE c.oid = i.inhrelid AND i.inhparent = '%s'\n"
3499 "ORDER BY c.oid::pg_catalog.regclass::pg_catalog.text;",
3513 if (is_partitioned && tuples == 0)
3533 const char *ct = is_partitioned ?
_(
"Partitions") :
_(
"Child tables");
3536 for (
i = 0;
i < tuples;
i++)
3548 if (child_relkind == RELKIND_PARTITIONED_TABLE ||
3549 child_relkind == RELKIND_PARTITIONED_INDEX)
3551 else if (child_relkind == RELKIND_FOREIGN_TABLE)
3564 if (tableinfo.reloftype)
3571 (tableinfo.relkind == RELKIND_RELATION ||
3572 tableinfo.relkind == RELKIND_MATVIEW) &&
3578 tableinfo.relreplident != REPLICA_IDENTITY_INDEX &&
3579 ((strcmp(schemaname,
"pg_catalog") != 0 &&
3580 tableinfo.relreplident != REPLICA_IDENTITY_DEFAULT) ||
3581 (strcmp(schemaname,
"pg_catalog") == 0 &&
3582 tableinfo.relreplident != REPLICA_IDENTITY_NOTHING)))
3584 const char *s =
_(
"Replica Identity");
3588 tableinfo.relreplident == REPLICA_IDENTITY_FULL ?
"FULL" :
3589 tableinfo.relreplident == REPLICA_IDENTITY_DEFAULT ?
"NOTHING" :
3596 if (
verbose && tableinfo.relkind != RELKIND_MATVIEW && tableinfo.hasoids)
3613 tableinfo.reloptions && tableinfo.reloptions[0] !=
'\0')
3615 const char *t =
_(
"Options");
3628 if (printTableInitialized)
3651 if (relkind == RELKIND_RELATION ||
3652 relkind == RELKIND_MATVIEW ||
3653 relkind == RELKIND_INDEX ||
3654 relkind == RELKIND_PARTITIONED_TABLE ||
3655 relkind == RELKIND_PARTITIONED_INDEX ||
3656 relkind == RELKIND_TOASTVALUE)
3669 "SELECT spcname FROM pg_catalog.pg_tablespace\n"
3722 const char align =
'l';
3730 "SELECT r.rolname, r.rolsuper, r.rolinherit,\n"
3731 " r.rolcreaterole, r.rolcreatedb, r.rolcanlogin,\n"
3732 " r.rolconnlimit, r.rolvaliduntil");
3748 if (!showSystem && !pattern)
3752 NULL,
"r.rolname", NULL, NULL,
3766 attr =
pg_malloc0((nrows + 1) *
sizeof(*attr));
3776 for (
i = 0;
i < nrows;
i++)
3838 for (
i = 0;
i < nrows;
i++)
3869 "pg_catalog.array_to_string(setconfig, E'\\n') AS \"%s\"\n"
3870 "FROM pg_catalog.pg_db_role_setting s\n"
3871 "LEFT JOIN pg_catalog.pg_database d ON d.oid = setdatabase\n"
3872 "LEFT JOIN pg_catalog.pg_roles r ON r.oid = setrole\n",
3877 NULL,
"r.rolname", NULL, NULL, &havewhere, 1))
3880 NULL,
"d.datname", NULL, NULL,
3898 if (pattern && pattern2)
3899 pg_log_error(
"Did not find any settings for role \"%s\" and database \"%s\".",
3902 pg_log_error(
"Did not find any settings for role \"%s\".",
3909 myopt.
title =
_(
"List of settings");
3936 "SELECT m.rolname AS \"%s\", r.rolname AS \"%s\",\n"
3937 " pg_catalog.concat_ws(', ',\n",
3943 " CASE WHEN pam.admin_option THEN 'ADMIN' END,\n"
3944 " CASE WHEN pam.inherit_option THEN 'INHERIT' END,\n"
3945 " CASE WHEN pam.set_option THEN 'SET' END\n");
3948 " CASE WHEN pam.admin_option THEN 'ADMIN' END,\n"
3949 " CASE WHEN m.rolinherit THEN 'INHERIT' END,\n"
3954 " g.rolname AS \"%s\"\n",
3959 "FROM pg_catalog.pg_roles m\n"
3960 " JOIN pg_catalog.pg_auth_members pam ON (pam.member = m.oid)\n"
3961 " LEFT JOIN pg_catalog.pg_roles r ON (pam.roleid = r.oid)\n"
3962 " LEFT JOIN pg_catalog.pg_roles g ON (pam.grantor = g.oid)\n");
3964 if (!showSystem && !pattern)
3968 NULL,
"m.rolname", NULL, NULL,
3982 myopt.
title =
_(
"List of role grants");
4009 bool showTables = strchr(tabtypes,
't') != NULL;
4010 bool showIndexes = strchr(tabtypes,
'i') != NULL;
4011 bool showViews = strchr(tabtypes,
'v') != NULL;
4012 bool showMatViews = strchr(tabtypes,
'm') != NULL;
4013 bool showSeq = strchr(tabtypes,
's') != NULL;
4014 bool showForeign = strchr(tabtypes,
'E') != NULL;
4021 bool translate_columns[] = {
false,
false,
true,
false,
false,
false,
false,
false,
false};
4024 ntypes = showTables + showIndexes + showViews + showMatViews +
4025 showSeq + showForeign;
4028 showTables = showViews = showMatViews = showSeq = showForeign =
true;
4033 "SELECT n.nspname as \"%s\",\n"
4034 " c.relname as \"%s\",\n"
4042 " WHEN " CppAsString2(RELKIND_FOREIGN_TABLE)
" THEN '%s'"
4043 " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE)
" THEN '%s'"
4044 " WHEN " CppAsString2(RELKIND_PARTITIONED_INDEX)
" THEN '%s'"
4046 " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
4065 ",\n c2.relname as \"%s\"",
4076 ",\n CASE c.relpersistence "
4077 "WHEN " CppAsString2(RELPERSISTENCE_PERMANENT)
" THEN '%s' "
4078 "WHEN " CppAsString2(RELPERSISTENCE_TEMP)
" THEN '%s' "
4079 "WHEN " CppAsString2(RELPERSISTENCE_UNLOGGED)
" THEN '%s' "
4085 translate_columns[cols_so_far] =
true;
4097 (showTables || showMatViews || showIndexes))
4099 ",\n am.amname as \"%s\"",
4103 ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_table_size(c.oid)) as \"%s\""
4104 ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
4110 "\nFROM pg_catalog.pg_class c"
4111 "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
4114 (showTables || showMatViews || showIndexes))
4116 "\n LEFT JOIN pg_catalog.pg_am am ON am.oid = c.relam");
4120 "\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
4121 "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
4129 if (showSystem || pattern)
4141 if (showSystem || pattern)
4149 if (!showSystem && !pattern)
4151 " AND n.nspname !~ '^pg_toast'\n"
4152 " AND n.nspname <> 'information_schema'\n");
4155 "n.nspname",
"c.relname", NULL,
4156 "pg_catalog.pg_table_is_visible(c.oid)",
4180 pg_log_error(
"Did not find any relations named \"%s\".",
4182 else if (showTables)
4185 else if (showIndexes)
4191 else if (showMatViews)
4192 pg_log_error(
"Did not find any materialized views named \"%s\".",
4195 pg_log_error(
"Did not find any sequences named \"%s\".",
4197 else if (showForeign)
4198 pg_log_error(
"Did not find any foreign tables named \"%s\".",
4208 else if (showTables)
4210 else if (showIndexes)
4214 else if (showMatViews)
4218 else if (showForeign)
4227 (ntypes != 1) ?
_(
"List of relations") :
4228 (showTables) ?
_(
"List of tables") :
4229 (showIndexes) ?
_(
"List of indexes") :
4230 (showViews) ?
_(
"List of views") :
4231 (showMatViews) ?
_(
"List of materialized views") :
4232 (showSeq) ?
_(
"List of sequences") :
4233 (showForeign) ?
_(
"List of foreign tables") :
4264 bool showTables = strchr(reltypes,
't') != NULL;
4265 bool showIndexes = strchr(reltypes,
'i') != NULL;
4266 bool showNested = strchr(reltypes,
'n') != NULL;
4271 bool translate_columns[] = {
false,
false,
false,
false,
false,
false,
false,
false,
false,
false};
4272 const char *tabletitle;
4273 bool mixed_output =
false;
4282 pg_log_error(
"The server (version %s) does not support declarative table partitioning.",
4284 sverbuf,
sizeof(sverbuf)));
4289 if (!showTables && !showIndexes)
4290 showTables = showIndexes =
true;
4292 if (showIndexes && !showTables)
4293 tabletitle =
_(
"List of partitioned indexes");
4294 else if (showTables && !showIndexes)
4295 tabletitle =
_(
"List of partitioned tables");
4299 tabletitle =
_(
"List of partitioned relations");
4300 mixed_output =
true;
4306 "SELECT n.nspname as \"%s\",\n"
4307 " c.relname as \"%s\",\n"
4308 " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
4316 ",\n CASE c.relkind"
4317 " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE)
" THEN '%s'"
4318 " WHEN " CppAsString2(RELKIND_PARTITIONED_INDEX)
" THEN '%s'"
4324 translate_columns[3] =
true;
4327 if (showNested || pattern)
4329 ",\n inh.inhparent::pg_catalog.regclass as \"%s\"",
4334 ",\n c2.oid::pg_catalog.regclass as \"%s\"",
4349 ",\n s.dps as \"%s\"",
4352 ",\n s.tps as \"%s\"",
4358 ",\n s.tps as \"%s\"",
4362 ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
4367 "\nFROM pg_catalog.pg_class c"
4368 "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
4372 "\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
4373 "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
4375 if (showNested || pattern)
4377 "\n LEFT JOIN pg_catalog.pg_inherits inh ON c.oid = inh.inhrelid");
4382 "\n LEFT JOIN pg_catalog.pg_am am ON c.relam = am.oid");
4387 ",\n LATERAL (WITH RECURSIVE d\n"
4388 " AS (SELECT inhrelid AS oid, 1 AS level\n"
4389 " FROM pg_catalog.pg_inherits\n"
4390 " WHERE inhparent = c.oid\n"
4392 " SELECT inhrelid, level + 1\n"
4393 " FROM pg_catalog.pg_inherits i\n"
4394 " JOIN d ON i.inhparent = d.oid)\n"
4395 " SELECT pg_catalog.pg_size_pretty(sum(pg_catalog.pg_table_size("
4396 "d.oid))) AS tps,\n"
4397 " pg_catalog.pg_size_pretty(sum("
4398 "\n CASE WHEN d.level = 1"
4399 " THEN pg_catalog.pg_table_size(d.oid) ELSE 0 END)) AS dps\n"
4406 ",\n LATERAL (SELECT pg_catalog.pg_size_pretty(sum("
4407 "\n CASE WHEN ppt.isleaf AND ppt.level = 1"
4408 "\n THEN pg_catalog.pg_table_size(ppt.relid)"
4409 " ELSE 0 END)) AS dps"
4410 ",\n pg_catalog.pg_size_pretty(sum("
4411 "pg_catalog.pg_table_size(ppt.relid))) AS tps"
4412 "\n FROM pg_catalog.pg_partition_tree(c.oid) ppt) s");
4425 " AND NOT c.relispartition\n" :
"");
4429 " AND n.nspname !~ '^pg_toast'\n"
4430 " AND n.nspname <> 'information_schema'\n");
4433 "n.nspname",
"c.relname", NULL,
4434 "pg_catalog.pg_table_is_visible(c.oid)",
4442 mixed_output ?
"\"Type\" DESC, " :
"",
4443 showNested || pattern ?
"\"Parent name\" NULLS FIRST, " :
"");
4481 "SELECT l.lanname AS \"%s\",\n"
4482 " pg_catalog.pg_get_userbyid(l.lanowner) as \"%s\",\n"
4483 " l.lanpltrusted AS \"%s\"",
4491 ",\n NOT l.lanispl AS \"%s\",\n"
4492 " l.lanplcallfoid::pg_catalog.regprocedure AS \"%s\",\n"
4493 " l.lanvalidator::pg_catalog.regprocedure AS \"%s\",\n "
4494 "l.laninline::pg_catalog.regprocedure AS \"%s\",\n ",
4503 ",\n d.description AS \"%s\""
4504 "\nFROM pg_catalog.pg_language l\n"
4505 "LEFT JOIN pg_catalog.pg_description d\n"
4506 " ON d.classoid = l.tableoid AND d.objoid = l.oid\n"
4507 " AND d.objsubid = 0\n",
4513 NULL,
"l.lanname", NULL, NULL,
4521 if (!showSystem && !pattern)
4532 myopt.
title =
_(
"List of languages");
4557 "SELECT n.nspname as \"%s\",\n"
4558 " t.typname as \"%s\",\n"
4559 " pg_catalog.format_type(t.typbasetype, t.typtypmod) as \"%s\",\n"
4560 " (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type bt\n"
4561 " WHERE c.oid = t.typcollation AND bt.oid = t.typbasetype AND t.typcollation <> bt.typcollation) as \"%s\",\n"
4562 " CASE WHEN t.typnotnull THEN 'not null' END as \"%s\",\n"
4563 " t.typdefault as \"%s\",\n"
4564 " pg_catalog.array_to_string(ARRAY(\n"
4565 " 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"
4566 " ), ' ') as \"%s\"",
4580 ",\n d.description as \"%s\"",
4585 "\nFROM pg_catalog.pg_type t\n"
4586 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
4590 " LEFT JOIN pg_catalog.pg_description d "
4591 "ON d.classoid = t.tableoid AND d.objoid = t.oid "
4592 "AND d.objsubid = 0\n");
4596 if (!showSystem && !pattern)
4598 " AND n.nspname <> 'information_schema'\n");
4601 "n.nspname",
"t.typname", NULL,
4602 "pg_catalog.pg_type_is_visible(t.oid)",
4616 myopt.
title =
_(
"List of domains");
4636 static const bool translate_columns[] =
4637 {
false,
false,
false,
false,
true,
false};
4642 "SELECT n.nspname AS \"%s\",\n"
4643 " c.conname AS \"%s\",\n"
4644 " pg_catalog.pg_encoding_to_char(c.conforencoding) AS \"%s\",\n"
4645 " pg_catalog.pg_encoding_to_char(c.contoencoding) AS \"%s\",\n"
4646 " CASE WHEN c.condefault THEN '%s'\n"
4647 " ELSE '%s' END AS \"%s\"",
4657 ",\n d.description AS \"%s\"",
4661 "\nFROM pg_catalog.pg_conversion c\n"
4662 " JOIN pg_catalog.pg_namespace n "
4663 "ON n.oid = c.connamespace\n");
4667 "LEFT JOIN pg_catalog.pg_description d "
4668 "ON d.classoid = c.tableoid\n"
4669 " AND d.objoid = c.oid "
4670 "AND d.objsubid = 0\n");
4674 if (!showSystem && !pattern)
4676 " AND n.nspname <> 'information_schema'\n");
4679 "n.nspname",
"c.conname", NULL,
4680 "pg_catalog.pg_conversion_is_visible(c.oid)",
4694 myopt.
title =
_(
"List of conversions");
4720 "SELECT s.name AS \"%s\", "
4721 "pg_catalog.current_setting(s.name) AS \"%s\"",
4728 ", s.vartype AS \"%s\", s.context AS \"%s\", ",
4742 " LEFT JOIN pg_catalog.pg_parameter_acl p\n"
4743 " ON pg_catalog.lower(s.name) = p.parname\n");
4748 NULL,
"pg_catalog.lower(s.name)", NULL,
4752 " s.setting IS DISTINCT FROM s.boot_val\n");
4762 myopt.
title =
_(
"List of configuration parameters");
4764 myopt.
title =
_(
"List of non-default configuration parameters");
4784 static const bool translate_columns[] =
4785 {
false,
false,
false,
true,
false,
false,
false};
4791 pg_log_error(
"The server (version %s) does not support event triggers.",
4793 sverbuf,
sizeof(sverbuf)));
4800 "SELECT evtname as \"%s\", "
4801 "evtevent as \"%s\", "
4802 "pg_catalog.pg_get_userbyid(e.evtowner) as \"%s\",\n"
4803 " case evtenabled when 'O' then '%s'"
4804 " when 'R' then '%s'"
4805 " when 'A' then '%s'"
4806 " when 'D' then '%s' end as \"%s\",\n"
4807 " e.evtfoid::pg_catalog.regproc as \"%s\", "
4808 "pg_catalog.array_to_string(array(select x"
4809 " from pg_catalog.unnest(evttags) as t(x)), ', ') as \"%s\"",
4822 ",\npg_catalog.obj_description(e.oid, 'pg_event_trigger') as \"%s\"",
4825 "\nFROM pg_catalog.pg_event_trigger e ");
4828 NULL,
"evtname", NULL, NULL,
4842 myopt.
title =
_(
"List of event triggers");
4869 pg_log_error(
"The server (version %s) does not support extended statistics.",
4871 sverbuf,
sizeof(sverbuf)));
4878 "es.stxnamespace::pg_catalog.regnamespace::pg_catalog.text AS \"%s\", \n"
4879 "es.stxname AS \"%s\", \n",
4885 "pg_catalog.format('%%s FROM %%s', \n"
4886 " pg_catalog.pg_get_statisticsobjdef_columns(es.oid), \n"
4887 " es.stxrelid::pg_catalog.regclass) AS \"%s\"",
4891 "pg_catalog.format('%%s FROM %%s', \n"
4892 " (SELECT pg_catalog.string_agg(pg_catalog.quote_ident(a.attname),', ') \n"
4893 " FROM pg_catalog.unnest(es.stxkeys) s(attnum) \n"
4894 " JOIN pg_catalog.pg_attribute a \n"
4895 " ON (es.stxrelid = a.attrelid \n"
4896 " AND a.attnum = s.attnum \n"
4897 " AND NOT a.attisdropped)), \n"
4898 "es.stxrelid::pg_catalog.regclass) AS \"%s\"",
4902 ",\nCASE WHEN " CppAsString2(STATS_EXT_NDISTINCT)
" = any(es.stxkind) THEN 'defined' \n"
4904 "CASE WHEN " CppAsString2(STATS_EXT_DEPENDENCIES)
" = any(es.stxkind) THEN 'defined' \n"
4915 ",\nCASE WHEN " CppAsString2(STATS_EXT_MCV)
" = any(es.stxkind) THEN 'defined' \n"
4921 " \nFROM pg_catalog.pg_statistic_ext es \n");
4925 "es.stxnamespace::pg_catalog.regnamespace::pg_catalog.text",
"es.stxname",
4926 NULL,
"pg_catalog.pg_statistics_obj_is_visible(es.oid)",
4940 myopt.
title =
_(
"List of extended statistics");
4960 static const bool translate_columns[] = {
false,
false,
false,
true,
true,
false};
4965 "SELECT pg_catalog.format_type(castsource, NULL) AS \"%s\",\n"
4966 " pg_catalog.format_type(casttarget, NULL) AS \"%s\",\n",
4976 " CASE WHEN c.castmethod = '%c' THEN '(binary coercible)'\n"
4977 " WHEN c.castmethod = '%c' THEN '(with inout)'\n"
4979 " END AS \"%s\",\n",
4980 COERCION_METHOD_BINARY,
4981 COERCION_METHOD_INOUT,
4985 " CASE WHEN c.castcontext = '%c' THEN '%s'\n"
4986 " WHEN c.castcontext = '%c' THEN '%s'\n"
4989 COERCION_CODE_EXPLICIT,
4991 COERCION_CODE_ASSIGNMENT,
4998 ",\n CASE WHEN p.proleakproof THEN '%s'\n"
5001 " d.description AS \"%s\"",
5012 "\nFROM pg_catalog.pg_cast c LEFT JOIN pg_catalog.pg_proc p\n"
5013 " ON c.castfunc = p.oid\n"
5014 " LEFT JOIN pg_catalog.pg_type ts\n"
5015 " ON c.castsource = ts.oid\n"
5016 " LEFT JOIN pg_catalog.pg_namespace ns\n"
5017 " ON ns.oid = ts.typnamespace\n"
5018 " LEFT JOIN pg_catalog.pg_type tt\n"
5019 " ON c.casttarget = tt.oid\n"
5020 " LEFT JOIN pg_catalog.pg_namespace nt\n"
5021 " ON nt.oid = tt.typnamespace\n");
5025 " LEFT JOIN pg_catalog.pg_description d\n"
5026 " ON d.classoid = c.tableoid AND d.objoid = "
5027 "c.oid AND d.objsubid = 0\n");
5036 "ns.nspname",
"ts.typname",
5037 "pg_catalog.format_type(ts.oid, NULL)",
5038 "pg_catalog.pg_type_is_visible(ts.oid)",
5045 "nt.nspname",
"tt.typname",
5046 "pg_catalog.format_type(tt.oid, NULL)",
5047 "pg_catalog.pg_type_is_visible(tt.oid)",
5058 myopt.
title =
_(
"List of casts");
5084 static const bool translate_columns[] = {
false,
false,
false,
false,
false,
false,
false,
true,
false};
5090 " n.nspname AS \"%s\",\n"
5091 " c.collname AS \"%s\",\n",
5097 " CASE c.collprovider "
5098 "WHEN " CppAsString2(COLLPROVIDER_DEFAULT)
" THEN 'default' "
5099 "WHEN " CppAsString2(COLLPROVIDER_BUILTIN)
" THEN 'builtin' "
5100 "WHEN " CppAsString2(COLLPROVIDER_LIBC)
" THEN 'libc' "
5106 " 'libc' AS \"%s\",\n",
5110 " c.collcollate AS \"%s\",\n"
5111 " c.collctype AS \"%s\",\n",
5117 " c.colllocale AS \"%s\",\n",
5121 " c.colliculocale AS \"%s\",\n",
5125 " c.collcollate AS \"%s\",\n",
5130 " c.collicurules AS \"%s\",\n",
5134 " NULL AS \"%s\",\n",
5139 " CASE WHEN c.collisdeterministic THEN '%s' ELSE '%s' END AS \"%s\"",
5150 ",\n pg_catalog.obj_description(c.oid, 'pg_collation') AS \"%s\"",
5154 "\nFROM pg_catalog.pg_collation c, pg_catalog.pg_namespace n\n"
5155 "WHERE n.oid = c.collnamespace\n");
5157 if (!showSystem && !pattern)
5159 " AND n.nspname <> 'information_schema'\n");
5167 appendPQExpBufferStr(&
buf,
" AND c.collencoding IN (-1, pg_catalog.pg_char_to_encoding(pg_catalog.getdatabaseencoding()))\n");
5170 "n.nspname",
"c.collname", NULL,
5171 "pg_catalog.pg_collation_is_visible(c.oid)",
5185 myopt.
title =
_(
"List of collations");
5207 int pub_schema_tuples = 0;
5208 char **footers = NULL;
5212 "SELECT n.nspname AS \"%s\",\n"
5213 " pg_catalog.pg_get_userbyid(n.nspowner) AS \"%s\"",
5222 ",\n pg_catalog.obj_description(n.oid, 'pg_namespace') AS \"%s\"",
5227 "\nFROM pg_catalog.pg_namespace n\n");
5229 if (!showSystem && !pattern)
5231 "WHERE n.nspname !~ '^pg_' AND n.nspname <> 'information_schema'\n");
5234 !showSystem && !pattern,
false,
5235 NULL,
"n.nspname", NULL,
5246 myopt.
title =
_(
"List of schemas");
5256 "FROM pg_catalog.pg_publication p\n"
5257 " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n"
5258 " JOIN pg_catalog.pg_namespace n ON n.oid = pn.pnnspid \n"
5259 "WHERE n.nspname = '%s'\n"
5268 if (pub_schema_tuples > 0)
5275 footers = (
char **)
pg_malloc((1 + pub_schema_tuples + 1) *
sizeof(
char *));
5279 for (
i = 0;
i < pub_schema_tuples;
i++)
5287 footers[
i + 1] = NULL;
5302 char **footer = NULL;
5304 for (footer = footers; *footer; footer++)
5336 " n.nspname as \"%s\",\n"
5337 " p.prsname as \"%s\",\n"
5338 " pg_catalog.obj_description(p.oid, 'pg_ts_parser') as \"%s\"\n"
5339 "FROM pg_catalog.pg_ts_parser p\n"
5340 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.prsnamespace\n",
5347 "n.nspname",
"p.prsname", NULL,
5348 "pg_catalog.pg_ts_parser_is_visible(p.oid)",
5362 myopt.
title =
_(
"List of text search parsers");
5387 "FROM pg_catalog.pg_ts_parser p\n"
5388 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.prsnamespace\n"
5392 "n.nspname",
"p.prsname", NULL,
5393 "pg_catalog.pg_ts_parser_is_visible(p.oid)",
5412 pg_log_error(
"Did not find any text search parser named \"%s\".",
5424 const char *nspname = NULL;
5425 const char *prsname;
5456 static const bool translate_columns[] = {
true,
false,
false};
5461 "SELECT '%s' AS \"%s\",\n"
5462 " p.prsstart::pg_catalog.regproc AS \"%s\",\n"
5463 " pg_catalog.obj_description(p.prsstart, 'pg_proc') as \"%s\"\n"
5464 " FROM pg_catalog.pg_ts_parser p\n"
5465 " WHERE p.oid = '%s'\n"
5468 " p.prstoken::pg_catalog.regproc,\n"
5469 " pg_catalog.obj_description(p.prstoken, 'pg_proc')\n"
5470 " FROM pg_catalog.pg_ts_parser p\n"
5471 " WHERE p.oid = '%s'\n"
5474 " p.prsend::pg_catalog.regproc,\n"
5475 " pg_catalog.obj_description(p.prsend, 'pg_proc')\n"
5476 " FROM pg_catalog.pg_ts_parser p\n"
5477 " WHERE p.oid = '%s'\n"
5480 " p.prsheadline::pg_catalog.regproc,\n"
5481 " pg_catalog.obj_description(p.prsheadline, 'pg_proc')\n"
5482 " FROM pg_catalog.pg_ts_parser p\n"
5483 " WHERE p.oid = '%s'\n"
5486 " p.prslextype::pg_catalog.regproc,\n"
5487 " pg_catalog.obj_description(p.prslextype, 'pg_proc')\n"
5488 " FROM pg_catalog.pg_ts_parser p\n"
5489 " WHERE p.oid = '%s';",
5529 "SELECT t.alias as \"%s\",\n"
5530 " t.description as \"%s\"\n"
5531 "FROM pg_catalog.ts_token_type( '%s'::pg_catalog.oid ) as t\n"
5580 " n.nspname as \"%s\",\n"
5581 " d.dictname as \"%s\",\n",
5588 " ( SELECT COALESCE(nt.nspname, '(null)')::pg_catalog.text || '.' || t.tmplname FROM\n"
5589 " pg_catalog.pg_ts_template t\n"
5590 " LEFT JOIN pg_catalog.pg_namespace nt ON nt.oid = t.tmplnamespace\n"
5591 " WHERE d.dicttemplate = t.oid ) AS \"%s\",\n"
5592 " d.dictinitoption as \"%s\",\n",
5598 " pg_catalog.obj_description(d.oid, 'pg_ts_dict') as \"%s\"\n",
5602 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.dictnamespace\n");
5605 "n.nspname",
"d.dictname", NULL,
5606 "pg_catalog.pg_ts_dict_is_visible(d.oid)",
5620 myopt.
title =
_(
"List of text search dictionaries");
5646 " n.nspname AS \"%s\",\n"
5647 " t.tmplname AS \"%s\",\n"
5648 " t.tmplinit::pg_catalog.regproc AS \"%s\",\n"
5649 " t.tmpllexize::pg_catalog.regproc AS \"%s\",\n"
5650 " pg_catalog.obj_description(t.oid, 'pg_ts_template') AS \"%s\"\n",
5659 " n.nspname AS \"%s\",\n"
5660 " t.tmplname AS \"%s\",\n"
5661 " pg_catalog.obj_description(t.oid, 'pg_ts_template') AS \"%s\"\n",
5667 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.tmplnamespace\n");
5670 "n.nspname",
"t.tmplname", NULL,
5671 "pg_catalog.pg_ts_template_is_visible(t.oid)",
5685 myopt.
title =
_(
"List of text search templates");
5713 " n.nspname as \"%s\",\n"
5714 " c.cfgname as \"%s\",\n"
5715 " pg_catalog.obj_description(c.oid, 'pg_ts_config') as \"%s\"\n"
5716 "FROM pg_catalog.pg_ts_config c\n"
5717 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.cfgnamespace\n",
5724 "n.nspname",
"c.cfgname", NULL,
5725 "pg_catalog.pg_ts_config_is_visible(c.oid)",
5739 myopt.
title =
_(
"List of text search configurations");
5758 "SELECT c.oid, c.cfgname,\n"
5761 " np.nspname as pnspname\n"
5762 "FROM pg_catalog.pg_ts_config c\n"
5763 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.cfgnamespace,\n"
5764 " pg_catalog.pg_ts_parser p\n"
5765 " LEFT JOIN pg_catalog.pg_namespace np ON np.oid = p.prsnamespace\n"
5766 "WHERE p.oid = c.cfgparser\n"
5770 "n.nspname",
"c.cfgname", NULL,
5771 "pg_catalog.pg_ts_config_is_visible(c.oid)",
5790 pg_log_error(
"Did not find any text search configuration named \"%s\".",
5793 pg_log_error(
"Did not find any text search configurations.");
5802 const char *cfgname;
5803 const char *nspname = NULL;
5804 const char *prsname;
5805 const char *pnspname = NULL;
5834 const char *pnspname,
const char *prsname)
5845 " ( SELECT t.alias FROM\n"
5846 " pg_catalog.ts_token_type(c.cfgparser) AS t\n"
5847 " WHERE t.tokid = m.maptokentype ) AS \"%s\",\n"
5848 " pg_catalog.btrim(\n"
5849 " ARRAY( SELECT mm.mapdict::pg_catalog.regdictionary\n"
5850 " FROM pg_catalog.pg_ts_config_map AS mm\n"
5851 " WHERE mm.mapcfg = m.mapcfg AND mm.maptokentype = m.maptokentype\n"
5852 " ORDER BY mapcfg, maptokentype, mapseqno\n"
5853 " ) :: pg_catalog.text,\n"
5854 " '{}') AS \"%s\"\n"
5855 "FROM pg_catalog.pg_ts_config AS c, pg_catalog.pg_ts_config_map AS m\n"
5856 "WHERE c.oid = '%s' AND m.mapcfg = c.oid\n"
5857 "GROUP BY m.mapcfg, m.maptokentype, c.cfgparser\n"
5912 "SELECT fdw.fdwname AS \"%s\",\n"
5913 " pg_catalog.pg_get_userbyid(fdw.fdwowner) AS \"%s\",\n"
5914 " fdw.fdwhandler::pg_catalog.regproc AS \"%s\",\n"
5915 " fdw.fdwvalidator::pg_catalog.regproc AS \"%s\"",
5926 ",\n CASE WHEN fdwoptions IS NULL THEN '' ELSE "
5927 " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
5928 " pg_catalog.quote_ident(option_name) || ' ' || "
5929 " pg_catalog.quote_literal(option_value) FROM "
5930 " pg_catalog.pg_options_to_table(fdwoptions)), ', ') || ')' "
5932 ",\n d.description AS \"%s\" ",
5941 "LEFT JOIN pg_catalog.pg_description d\n"
5942 " ON d.classoid = fdw.tableoid "
5943 "AND d.objoid = fdw.oid AND d.objsubid = 0\n");
5946 NULL,
"fdwname", NULL, NULL,
5960 myopt.
title =
_(
"List of foreign-data wrappers");
5983 "SELECT s.srvname AS \"%s\",\n"
5984 " pg_catalog.pg_get_userbyid(s.srvowner) AS \"%s\",\n"
5985 " f.fdwname AS \"%s\"",
5996 " s.srvtype AS \"%s\",\n"
5997 " s.srvversion AS \"%s\",\n"
5998 " CASE WHEN srvoptions IS NULL THEN '' ELSE "
5999 " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
6000 " pg_catalog.quote_ident(option_name) || ' ' || "
6001 " pg_catalog.quote_literal(option_value) FROM "
6002 " pg_catalog.pg_options_to_table(srvoptions)), ', ') || ')' "
6004 " d.description AS \"%s\"",
6012 "\nFROM pg_catalog.pg_foreign_server s\n"
6013 " JOIN pg_catalog.pg_foreign_data_wrapper f ON f.oid=s.srvfdw\n");
6017 "LEFT JOIN pg_catalog.pg_description d\n "
6018 "ON d.classoid = s.tableoid AND d.objoid = s.oid "
6019 "AND d.objsubid = 0\n");
6022 NULL,
"s.srvname", NULL, NULL,
6036 myopt.
title =
_(
"List of foreign servers");
6059 "SELECT um.srvname AS \"%s\",\n"
6060 " um.usename AS \"%s\"",
6066 ",\n CASE WHEN umoptions IS NULL THEN '' ELSE "
6067 " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
6068 " pg_catalog.quote_ident(option_name) || ' ' || "
6069 " pg_catalog.quote_literal(option_value) FROM "
6070 " pg_catalog.pg_options_to_table(umoptions)), ', ') || ')' "
6077 NULL,
"um.srvname",
"um.usename", NULL,
6091 myopt.
title =
_(
"List of user mappings");
6114 "SELECT n.nspname AS \"%s\",\n"
6115 " c.relname AS \"%s\",\n"
6116 " s.srvname AS \"%s\"",
6123 ",\n CASE WHEN ftoptions IS NULL THEN '' ELSE "
6124 " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
6125 " pg_catalog.quote_ident(option_name) || ' ' || "
6126 " pg_catalog.quote_literal(option_value) FROM "
6127 " pg_catalog.pg_options_to_table(ftoptions)), ', ') || ')' "
6129 " d.description AS \"%s\"",
6134 "\nFROM pg_catalog.pg_foreign_table ft\n"
6135 " INNER JOIN pg_catalog.pg_class c"
6136 " ON c.oid = ft.ftrelid\n"
6137 " INNER JOIN pg_catalog.pg_namespace n"
6138 " ON n.oid = c.relnamespace\n"
6139 " INNER JOIN pg_catalog.pg_foreign_server s"
6140 " ON s.oid = ft.ftserver\n");
6143 " LEFT JOIN pg_catalog.pg_description d\n"
6144 " ON d.classoid = c.tableoid AND "
6145 "d.objoid = c.oid AND d.objsubid = 0\n");
6148 "n.nspname",
"c.relname", NULL,
6149 "pg_catalog.pg_table_is_visible(c.oid)",
6163 myopt.
title =
_(
"List of foreign tables");
6186 "SELECT e.extname AS \"%s\", "
6187 "e.extversion AS \"%s\", ae.default_version AS \"%s\","
6188 "n.nspname AS \"%s\", d.description AS \"%s\"\n"
6189 "FROM pg_catalog.pg_extension e "
6190 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = e.extnamespace "
6191 "LEFT JOIN pg_catalog.pg_description d ON d.objoid = e.oid "
6192 "AND d.classoid = 'pg_catalog.pg_extension'::pg_catalog.regclass "
6193 "LEFT JOIN pg_catalog.pg_available_extensions() ae(name, default_version, comment) ON ae.name = e.extname\n",
6202 NULL,
"e.extname", NULL,
6217 myopt.
title =
_(
"List of installed extensions");
6240 "SELECT e.extname, e.oid\n"
6241 "FROM pg_catalog.pg_extension e\n");
6245 NULL,
"e.extname", NULL,
6265 pg_log_error(
"Did not find any extension named \"%s\".",
6276 const char *extname;
6308 "SELECT pg_catalog.pg_describe_object(classid, objid, 0) AS \"%s\"\n"
6309 "FROM pg_catalog.pg_depend\n"
6310 "WHERE refclassid = 'pg_catalog.pg_extension'::pg_catalog.regclass AND refobjid = '%s' AND deptype = 'e'\n"
6344 bool force_escape,
const char *schemavar,
6345 const char *namevar,
const char *altnamevar,
6346 const char *visibilityrule,
bool *added_clause,
6355 schemavar, namevar, altnamevar,
6356 visibilityrule, &dbbuf, &dotcnt);
6357 if (added_clause != NULL)
6358 *added_clause = added;
6360 if (dotcnt >= maxparts)
6362 pg_log_error(
"improper qualified name (too many dotted names): %s",
6367 if (maxparts > 1 && dotcnt == maxparts - 1)
6371 pg_log_error(
"You are currently not connected to a database.");
6376 pg_log_error(
"cross-database references are not implemented: %s",
6401 static const bool translate_columns[] = {
false,
false,
false,
false,
false,
false,
false,
false,
false};
6407 pg_log_error(
"The server (version %s) does not support publications.",
6409 sverbuf,
sizeof(sverbuf)));
6416 "SELECT pubname AS \"%s\",\n"
6417 " pg_catalog.pg_get_userbyid(pubowner) AS \"%s\",\n"
6418 " puballtables AS \"%s\",\n"
6419 " pubinsert AS \"%s\",\n"
6420 " pubupdate AS \"%s\",\n"
6421 " pubdelete AS \"%s\"",
6430 ",\n pubtruncate AS \"%s\"",
6434 ",\n (CASE pubgencols\n"
6435 " WHEN '%c' THEN 'none'\n"
6436 " WHEN '%c' THEN 'stored'\n"
6438 PUBLISH_GENCOLS_NONE,
6439 PUBLISH_GENCOLS_STORED,
6443 ",\n pubviaroot AS \"%s\"",
6447 "\nFROM pg_catalog.pg_publication\n");
6450 NULL,
"pubname", NULL,
6465 myopt.
title =
_(
"List of publications");
6497 for (
i = 0;
i < count;
i++)
6532 bool has_pubtruncate;
6533 bool has_pubgencols;
6534 bool has_pubviaroot;
6543 pg_log_error(
"The server (version %s) does not support publications.",
6545 sverbuf,
sizeof(sverbuf)));
6556 "SELECT oid, pubname,\n"
6557 " pg_catalog.pg_get_userbyid(pubowner) AS owner,\n"
6558 " puballtables, pubinsert, pubupdate, pubdelete");
6559 if (has_pubtruncate)
6564 ", false AS pubtruncate");
6568 ", (CASE pubgencols\n"
6569 " WHEN '%c' THEN 'none'\n"
6570 " WHEN '%c' THEN 'stored'\n"
6571 " END) AS \"%s\"\n",
6572 PUBLISH_GENCOLS_NONE,
6573 PUBLISH_GENCOLS_STORED,
6577 ", 'none' AS pubgencols");
6584 ", false AS pubviaroot");
6587 "\nFROM pg_catalog.pg_publication\n");
6590 NULL,
"pubname", NULL,
6612 pg_log_error(
"Did not find any publication named \"%s\".",
6625 const char align =
'l';
6630 bool puballtables = strcmp(
PQgetvalue(res,
i, 3),
"t") == 0;
6633 if (has_pubtruncate)
6649 if (has_pubtruncate)
6661 if (has_pubtruncate)
6672 "SELECT n.nspname, c.relname");
6676 ", pg_get_expr(pr.prqual, c.oid)");
6678 ", (CASE WHEN pr.prattrs IS NOT NULL THEN\n"
6679 " pg_catalog.array_to_string("
6680 " ARRAY(SELECT attname\n"
6682 " pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n"
6683 " pg_catalog.pg_attribute\n"
6684 " WHERE attrelid = c.oid AND attnum = prattrs[s]), ', ')\n"
6691 "\nFROM pg_catalog.pg_class c,\n"
6692 " pg_catalog.pg_namespace n,\n"
6693 " pg_catalog.pg_publication_rel pr\n"
6694 "WHERE c.relnamespace = n.oid\n"
6695 " AND c.oid = pr.prrelid\n"
6696 " AND pr.prpubid = '%s'\n"
6697 "ORDER BY 1,2", pubid);
6705 "SELECT n.nspname\n"
6706 "FROM pg_catalog.pg_namespace n\n"
6707 " JOIN pg_catalog.pg_publication_namespace pn ON n.oid = pn.pnnspid\n"
6708 "WHERE pn.pnpubid = '%s'\n"
6709 "ORDER BY 1", pubid);
6747 static const bool translate_columns[] = {
false,
false,
false,
false,
6748 false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
6749 false,
false,
false,
false};
6755 pg_log_error(
"The server (version %s) does not support subscriptions.",
6757 sverbuf,
sizeof(sverbuf)));
6764 "SELECT subname AS \"%s\"\n"
6765 ", pg_catalog.pg_get_userbyid(subowner) AS \"%s\"\n"
6766 ", subenabled AS \"%s\"\n"
6767 ", subpublications AS \"%s\"\n",
6779 ", subbinary AS \"%s\"\n",
6784 ", (CASE substream\n"
6785 " WHEN " CppAsString2(LOGICALREP_STREAM_OFF)
" THEN 'off'\n"
6786 " WHEN " CppAsString2(LOGICALREP_STREAM_ON)
" THEN 'on'\n"
6787 " WHEN " CppAsString2(LOGICALREP_STREAM_PARALLEL)
" THEN 'parallel'\n"
6788 " END) AS \"%s\"\n",
6792 ", substream AS \"%s\"\n",
6799 ", subtwophasestate AS \"%s\"\n"
6800 ", subdisableonerr AS \"%s\"\n",
6806 ", suborigin AS \"%s\"\n"
6807 ", subpasswordrequired AS \"%s\"\n"
6808 ", subrunasowner AS \"%s\"\n",
6815 ", subfailover AS \"%s\"\n",
6820 ", subretaindeadtuples AS \"%s\"\n",
6824 ", submaxretention AS \"%s\"\n",
6828 ", subretentionactive AS \"%s\"\n",
6833 ", subsynccommit AS \"%s\"\n"
6834 ", subconninfo AS \"%s\"\n",
6841 ", subskiplsn AS \"%s\"\n",
6847 "FROM pg_catalog.pg_subscription\n"
6848 "WHERE subdbid = (SELECT oid\n"
6849 " FROM pg_catalog.pg_database\n"
6850 " WHERE datname = pg_catalog.current_database())");
6853 NULL,
"subname", NULL,
6868 myopt.
title =
_(
"List of subscriptions");
6894 " WHEN pg_catalog.array_length(%s, 1) = 0 THEN '%s'"
6895 " ELSE pg_catalog.array_to_string(%s, E'\\n')"
6909 const char *type_pattern,
bool verbose)
6914 bool have_where =
false;
6915 static const bool translate_columns[] = {
false,
false,
false,
false,
false,
false,
false};
6921 " am.amname AS \"%s\",\n"
6922 " pg_catalog.format_type(c.opcintype, NULL) AS \"%s\",\n"
6924 " WHEN c.opckeytype <> 0 AND c.opckeytype <> c.opcintype\n"
6925 " THEN pg_catalog.format_type(c.opckeytype, NULL)\n"
6929 " WHEN pg_catalog.pg_opclass_is_visible(c.oid)\n"
6930 " THEN pg_catalog.format('%%I', c.opcname)\n"
6931 " ELSE pg_catalog.format('%%I.%%I', n.nspname, c.opcname)\n"
6933 " (CASE WHEN c.opcdefault\n"
6947 " WHEN pg_catalog.pg_opfamily_is_visible(of.oid)\n"
6948 " THEN pg_catalog.format('%%I', of.opfname)\n"
6949 " ELSE pg_catalog.format('%%I.%%I', ofn.nspname, of.opfname)\n"
6951 " pg_catalog.pg_get_userbyid(c.opcowner) AS \"%s\"\n",
6955 "\nFROM pg_catalog.pg_opclass c\n"
6956 " LEFT JOIN pg_catalog.pg_am am on am.oid = c.opcmethod\n"
6957 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.opcnamespace\n"
6958 " LEFT JOIN pg_catalog.pg_type t ON t.oid = c.opcintype\n"
6959 " LEFT JOIN pg_catalog.pg_namespace tn ON tn.oid = t.typnamespace\n");
6962 " LEFT JOIN pg_catalog.pg_opfamily of ON of.oid = c.opcfamily\n"
6963 " LEFT JOIN pg_catalog.pg_namespace ofn ON ofn.oid = of.opfnamespace\n");
6965 if (access_method_pattern)
6967 false,
false, NULL,
"am.amname", NULL, NULL,
6974 "tn.nspname",
"t.typname",
6975 "pg_catalog.format_type(t.oid, NULL)",
6976 "pg_catalog.pg_type_is_visible(t.oid)",
6987 myopt.
title =
_(
"List of operator classes");
7010 const char *type_pattern,
bool verbose)
7015 bool have_where =
false;
7016 static const bool translate_columns[] = {
false,
false,
false,
false};
7022 " am.amname AS \"%s\",\n"
7024 " WHEN pg_catalog.pg_opfamily_is_visible(f.oid)\n"
7025 " THEN pg_catalog.format('%%I', f.opfname)\n"
7026 " ELSE pg_catalog.format('%%I.%%I', n.nspname, f.opfname)\n"
7029 " pg_catalog.string_agg(pg_catalog.format_type(oc.opcintype, NULL), ', ')\n"
7030 " FROM pg_catalog.pg_opclass oc\n"
7031 " WHERE oc.opcfamily = f.oid) \"%s\"",
7037 ",\n pg_catalog.pg_get_userbyid(f.opfowner) AS \"%s\"\n",
7040 "\nFROM pg_catalog.pg_opfamily f\n"
7041 " LEFT JOIN pg_catalog.pg_am am on am.oid = f.opfmethod\n"
7042 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = f.opfnamespace\n");
7044 if (access_method_pattern)
7046 false,
false, NULL,
"am.amname", NULL, NULL,
7054 " FROM pg_catalog.pg_type t\n"
7055 " JOIN pg_catalog.pg_opclass oc ON oc.opcintype = t.oid\n"
7056 " LEFT JOIN pg_catalog.pg_namespace tn ON tn.oid = t.typnamespace\n"
7057 " WHERE oc.opcfamily = f.oid\n",
7058 have_where ?
"AND" :
"WHERE");
7061 "tn.nspname",
"t.typname",
7062 "pg_catalog.format_type(t.oid, NULL)",
7063 "pg_catalog.pg_type_is_visible(t.oid)",
7075 myopt.
title =
_(
"List of operator families");
7099 const char *family_pattern,
bool verbose)
7104 bool have_where =
false;
7106 static const bool translate_columns[] = {
false,
false,
false,
false,
false,
false,
true};
7112 " am.amname AS \"%s\",\n"
7114 " WHEN pg_catalog.pg_opfamily_is_visible(of.oid)\n"
7115 " THEN pg_catalog.format('%%I', of.opfname)\n"
7116 " ELSE pg_catalog.format('%%I.%%I', nsf.nspname, of.opfname)\n"
7118 " o.amopopr::pg_catalog.regoperator AS \"%s\"\n,"
7119 " o.amopstrategy AS \"%s\",\n"
7120 " CASE o.amoppurpose\n"
7134 ", ofs.opfname AS \"%s\",\n"
7136 " WHEN p.proleakproof THEN '%s'\n"
7144 "FROM pg_catalog.pg_amop o\n"
7145 " LEFT JOIN pg_catalog.pg_opfamily of ON of.oid = o.amopfamily\n"
7146 " LEFT JOIN pg_catalog.pg_am am ON am.oid = of.opfmethod AND am.oid = o.amopmethod\n"
7147 " LEFT JOIN pg_catalog.pg_namespace nsf ON of.opfnamespace = nsf.oid\n");
7150 " LEFT JOIN pg_catalog.pg_opfamily ofs ON ofs.oid = o.amopsortfamily\n"
7151 " LEFT JOIN pg_catalog.pg_operator op ON op.oid = o.amopopr\n"
7152 " LEFT JOIN pg_catalog.pg_proc p ON p.oid = op.oprcode\n");
7154 if (access_method_pattern)
7157 false,
false, NULL,
"am.amname",
7166 "nsf.nspname",
"of.opfname", NULL, NULL,
7172 " o.amoplefttype = o.amoprighttype DESC,\n"
7173 " pg_catalog.format_type(o.amoplefttype, NULL),\n"
7174 " pg_catalog.format_type(o.amoprighttype, NULL),\n"
7175 " o.amopstrategy;");
7182 myopt.
title =
_(
"List of operators of operator families");
7206 const char *family_pattern,
bool verbose)
7211 bool have_where =
false;
7212 static const bool translate_columns[] = {
false,
false,
false,
false,
false,
false};
7218 " am.amname AS \"%s\",\n"
7220 " WHEN pg_catalog.pg_opfamily_is_visible(of.oid)\n"
7221 " THEN pg_catalog.format('%%I', of.opfname)\n"
7222 " ELSE pg_catalog.format('%%I.%%I', ns.nspname, of.opfname)\n"
7224 " pg_catalog.format_type(ap.amproclefttype, NULL) AS \"%s\",\n"
7225 " pg_catalog.format_type(ap.amprocrighttype, NULL) AS \"%s\",\n"
7226 " ap.amprocnum AS \"%s\"\n",
7235 ", p.proname AS \"%s\"\n",
7239 ", ap.amproc::pg_catalog.regprocedure AS \"%s\"\n",
7243 "FROM pg_catalog.pg_amproc ap\n"
7244 " LEFT JOIN pg_catalog.pg_opfamily of ON of.oid = ap.amprocfamily\n"
7245 " LEFT JOIN pg_catalog.pg_am am ON am.oid = of.opfmethod\n"
7246 " LEFT JOIN pg_catalog.pg_namespace ns ON of.opfnamespace = ns.oid\n"
7247 " LEFT JOIN pg_catalog.pg_proc p ON ap.amproc = p.oid\n");
7249 if (access_method_pattern)
7252 false,
false, NULL,
"am.amname",
7260 "ns.nspname",
"of.opfname", NULL, NULL,
7266 " ap.amproclefttype = ap.amprocrighttype DESC,\n"
7274 myopt.
title =
_(
"List of support functions of operator families");
7303 "SELECT oid as \"%s\",\n"
7304 " pg_catalog.pg_get_userbyid(lomowner) as \"%s\",\n ",
7315 "pg_catalog.obj_description(oid, 'pg_largeobject') as \"%s\"\n"
7316 "FROM pg_catalog.pg_largeobject_metadata\n"
7325 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