18#include "catalog/pg_am_d.h"
19#include "catalog/pg_amop_d.h"
20#include "catalog/pg_attribute_d.h"
21#include "catalog/pg_cast_d.h"
22#include "catalog/pg_class_d.h"
23#include "catalog/pg_collation_d.h"
24#include "catalog/pg_constraint_d.h"
25#include "catalog/pg_default_acl_d.h"
26#include "catalog/pg_proc_d.h"
27#include "catalog/pg_publication_d.h"
28#include "catalog/pg_statistic_ext_d.h"
29#include "catalog/pg_subscription_d.h"
30#include "catalog/pg_type_d.h"
41 const char *relationname,
53 const char *pnspname,
const char *prsname);
57 bool have_where,
bool force_escape,
58 const char *schemavar,
const char *namevar,
59 const char *altnamevar,
60 const char *visibilityrule,
61 bool *added_clause,
int maxparts);
87 "SELECT n.nspname as \"%s\",\n"
88 " p.proname AS \"%s\",\n"
89 " pg_catalog.format_type(p.prorettype, NULL) AS \"%s\",\n"
90 " CASE WHEN p.pronargs = 0\n"
91 " THEN CAST('*' AS pg_catalog.text)\n"
92 " ELSE pg_catalog.pg_get_function_arguments(p.oid)\n"
101 " pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"\n"
102 "FROM pg_catalog.pg_proc p\n"
103 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n"
104 "WHERE p.prokind = " CppAsString2(PROKIND_AGGREGATE)
"\n",
108 " pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"\n"
109 "FROM pg_catalog.pg_proc p\n"
110 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n"
111 "WHERE p.proisagg\n",
114 if (!showSystem && !pattern)
116 " AND n.nspname <> 'information_schema'\n");
119 "n.nspname",
"p.proname", NULL,
120 "pg_catalog.pg_function_is_visible(p.oid)",
134 myopt.
title =
_(
"List of aggregate functions");
153 static const bool translate_columns[] = {
false,
true,
false,
false};
159 pg_log_error(
"The server (version %s) does not support access methods.",
161 sverbuf,
sizeof(sverbuf)));
168 "SELECT amname AS \"%s\",\n"
181 ",\n amhandler AS \"%s\",\n"
182 " pg_catalog.obj_description(oid, 'pg_am') AS \"%s\"",
188 "\nFROM pg_catalog.pg_am\n");
191 NULL,
"amname", NULL,
206 myopt.
title =
_(
"List of access methods");
231 "SELECT spcname AS \"%s\",\n"
232 " pg_catalog.pg_get_userbyid(spcowner) AS \"%s\",\n"
233 " pg_catalog.pg_tablespace_location(oid) AS \"%s\"",
243 ",\n spcoptions AS \"%s\""
244 ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_tablespace_size(oid)) AS \"%s\""
245 ",\n pg_catalog.shobj_description(oid, 'pg_tablespace') AS \"%s\"",
252 "\nFROM pg_catalog.pg_tablespace\n");
255 NULL,
"spcname", NULL,
270 myopt.
title =
_(
"List of tablespaces");
296 char **arg_patterns,
int num_arg_patterns,
299 bool showAggregate = strchr(functypes,
'a') != NULL;
300 bool showNormal = strchr(functypes,
'n') != NULL;
301 bool showProcedure = strchr(functypes,
'p') != NULL;
302 bool showTrigger = strchr(functypes,
't') != NULL;
303 bool showWindow = strchr(functypes,
'w') != NULL;
308 static const bool translate_columns[] = {
false,
false,
false,
false,
true,
true,
true,
false,
true,
true,
false,
false,
false,
false};
311 static const bool translate_columns_pre_96[] = {
false,
false,
false,
false,
true,
true,
false,
true,
true,
false,
false,
false,
false};
313 if (strlen(functypes) != strspn(functypes,
"anptwSx+"))
323 pg_log_error(
"\\df does not take a \"%c\" option with server version %s",
326 sverbuf,
sizeof(sverbuf)));
330 if (!showAggregate && !showNormal && !showProcedure && !showTrigger && !showWindow)
332 showAggregate = showNormal = showTrigger = showWindow =
true;
334 showProcedure =
true;
340 "SELECT n.nspname as \"%s\",\n"
341 " p.proname as \"%s\",\n",
347 " pg_catalog.pg_get_function_result(p.oid) as \"%s\",\n"
348 " pg_catalog.pg_get_function_arguments(p.oid) as \"%s\",\n"
365 " pg_catalog.pg_get_function_result(p.oid) as \"%s\",\n"
366 " pg_catalog.pg_get_function_arguments(p.oid) as \"%s\",\n"
368 " WHEN p.proisagg THEN '%s'\n"
369 " WHEN p.proiswindow THEN '%s'\n"
370 " WHEN p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype THEN '%s'\n"
386 " WHEN p.provolatile = "
388 " WHEN p.provolatile = "
390 " WHEN p.provolatile = "
400 " WHEN p.proparallel = "
402 " WHEN p.proparallel = "
404 " WHEN p.proparallel = "
412 ",\n pg_catalog.pg_get_userbyid(p.proowner) as \"%s\""
413 ",\n CASE WHEN prosecdef THEN '%s' ELSE '%s' END AS \"%s\""
414 ",\n CASE WHEN p.proleakproof THEN '%s' ELSE '%s' END as \"%s\"",
425 ",\n l.lanname as \"%s\"",
428 ",\n CASE WHEN l.lanname IN ('internal', 'c') THEN p.prosrc END as \"%s\"",
431 ",\n pg_catalog.obj_description(p.oid, 'pg_proc') as \"%s\"",
436 "\nFROM pg_catalog.pg_proc p"
437 "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.pronamespace\n");
439 for (
int i = 0;
i < num_arg_patterns;
i++)
442 " LEFT JOIN pg_catalog.pg_type t%d ON t%d.oid = p.proargtypes[%d]\n"
443 " LEFT JOIN pg_catalog.pg_namespace nt%d ON nt%d.oid = t%d.typnamespace\n",
449 " LEFT JOIN pg_catalog.pg_language l ON l.oid = p.prolang\n");
454 if (showNormal && showAggregate && showProcedure && showTrigger && showWindow)
514 bool needs_or =
false;
533 "p.prorettype = 'pg_catalog.trigger'::pg_catalog.regtype\n");
558 "n.nspname",
"p.proname", NULL,
559 "pg_catalog.pg_function_is_visible(p.oid)",
563 for (
int i = 0;
i < num_arg_patterns;
i++)
565 if (strcmp(arg_patterns[
i],
"-") != 0)
577 snprintf(nspname,
sizeof(nspname),
"nt%d.nspname",
i);
580 "pg_catalog.format_type(t%d.oid, NULL)",
i);
582 "pg_catalog.pg_type_is_visible(t%d.oid)",
i);
597 if (!showSystem && !func_pattern)
599 " AND n.nspname <> 'information_schema'\n");
608 myopt.
title =
_(
"List of functions");
647 "SELECT n.nspname as \"%s\",\n"
648 " pg_catalog.format_type(t.oid, NULL) AS \"%s\",\n",
654 " t.typname AS \"%s\",\n"
655 " CASE WHEN t.typrelid != 0\n"
656 " THEN CAST('tuple' AS pg_catalog.text)\n"
657 " WHEN t.typlen < 0\n"
658 " THEN CAST('var' AS pg_catalog.text)\n"
659 " ELSE CAST(t.typlen AS pg_catalog.text)\n"
661 " pg_catalog.array_to_string(\n"
663 " SELECT e.enumlabel\n"
664 " FROM pg_catalog.pg_enum e\n"
665 " WHERE e.enumtypid = t.oid\n"
666 " ORDER BY e.enumsortorder\n"
670 " pg_catalog.pg_get_userbyid(t.typowner) AS \"%s\",\n",
680 " pg_catalog.obj_description(t.oid, 'pg_type') as \"%s\"\n",
684 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
692 " FROM pg_catalog.pg_class c "
693 "WHERE c.oid = t.typrelid))\n");
698 if (pattern == NULL || strstr(pattern,
"[]") == NULL)
699 appendPQExpBufferStr(&
buf,
" AND NOT EXISTS(SELECT 1 FROM pg_catalog.pg_type el WHERE el.oid = t.typelem AND el.typarray = t.oid)\n");
701 if (!showSystem && !pattern)
703 " AND n.nspname <> 'information_schema'\n");
708 "n.nspname",
"t.typname",
709 "pg_catalog.format_type(t.oid, NULL)",
710 "pg_catalog.pg_type_is_visible(t.oid)",
724 myopt.
title =
_(
"List of data types");
745 static const char *
const typename_map[] = {
751 "decimal",
"numeric",
752 "float",
"double precision",
759 "bool[]",
"boolean[]",
760 "decimal[]",
"numeric[]",
761 "float[]",
"double precision[]",
762 "float4[]",
"real[]",
763 "float8[]",
"double precision[]",
764 "int[]",
"integer[]",
765 "int2[]",
"smallint[]",
766 "int4[]",
"integer[]",
767 "int8[]",
"bigint[]",
768 "time[]",
"time without time zone[]",
769 "timetz[]",
"time with time zone[]",
770 "timestamp[]",
"timestamp without time zone[]",
771 "timestamptz[]",
"timestamp with time zone[]",
772 "varbit[]",
"bit varying[]",
773 "varchar[]",
"character varying[]",
779 for (
int i = 0; typename_map[
i] != NULL;
i += 2)
782 return typename_map[
i + 1];
794 char **arg_patterns,
int num_arg_patterns,
800 static const bool translate_columns[] = {
false,
false,
false,
false,
false,
false,
true,
false};
821 "SELECT n.nspname as \"%s\",\n"
822 " o.oprname AS \"%s\",\n"
823 " CASE WHEN o.oprkind='l' THEN NULL ELSE pg_catalog.format_type(o.oprleft, NULL) END AS \"%s\",\n"
824 " CASE WHEN o.oprkind='r' THEN NULL ELSE pg_catalog.format_type(o.oprright, NULL) END AS \"%s\",\n"
825 " pg_catalog.format_type(o.oprresult, NULL) AS \"%s\",\n",
834 " o.oprcode AS \"%s\",\n"
835 " CASE WHEN p.proleakproof THEN '%s' ELSE '%s' END AS \"%s\",\n",
842 " coalesce(pg_catalog.obj_description(o.oid, 'pg_operator'),\n"
843 " pg_catalog.obj_description(o.oprcode, 'pg_proc')) AS \"%s\"\n"
844 "FROM pg_catalog.pg_operator o\n"
845 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = o.oprnamespace\n",
848 if (num_arg_patterns >= 2)
850 num_arg_patterns = 2;
852 " LEFT JOIN pg_catalog.pg_type t0 ON t0.oid = o.oprleft\n"
853 " LEFT JOIN pg_catalog.pg_namespace nt0 ON nt0.oid = t0.typnamespace\n"
854 " LEFT JOIN pg_catalog.pg_type t1 ON t1.oid = o.oprright\n"
855 " LEFT JOIN pg_catalog.pg_namespace nt1 ON nt1.oid = t1.typnamespace\n");
857 else if (num_arg_patterns == 1)
860 " LEFT JOIN pg_catalog.pg_type t0 ON t0.oid = o.oprright\n"
861 " LEFT JOIN pg_catalog.pg_namespace nt0 ON nt0.oid = t0.typnamespace\n");
866 " LEFT JOIN pg_catalog.pg_proc p ON p.oid = o.oprcode\n");
868 if (!showSystem && !oper_pattern)
870 " AND n.nspname <> 'information_schema'\n");
873 !showSystem && !oper_pattern,
true,
874 "n.nspname",
"o.oprname", NULL,
875 "pg_catalog.pg_operator_is_visible(o.oid)",
879 if (num_arg_patterns == 1)
882 for (
int i = 0;
i < num_arg_patterns;
i++)
884 if (strcmp(arg_patterns[
i],
"-") != 0)
896 snprintf(nspname,
sizeof(nspname),
"nt%d.nspname",
i);
899 "pg_catalog.format_type(t%d.oid, NULL)",
i);
901 "pg_catalog.pg_type_is_visible(t%d.oid)",
i);
923 myopt.
title =
_(
"List of operators");
955 " d.datname as \"%s\",\n"
956 " pg_catalog.pg_get_userbyid(d.datdba) as \"%s\",\n"
957 " pg_catalog.pg_encoding_to_char(d.encoding) as \"%s\",\n",
963 " CASE d.datlocprovider "
964 "WHEN " CppAsString2(COLLPROVIDER_BUILTIN)
" THEN 'builtin' "
971 " 'libc' AS \"%s\",\n",
974 " d.datcollate as \"%s\",\n"
975 " d.datctype as \"%s\",\n",
980 " d.datlocale as \"%s\",\n",
984 " d.daticulocale as \"%s\",\n",
988 " NULL as \"%s\",\n",
992 " d.daticurules as \"%s\",\n",
996 " NULL as \"%s\",\n",
1002 ",\n CASE WHEN pg_catalog.has_database_privilege(d.datname, 'CONNECT')\n"
1003 " THEN pg_catalog.pg_size_pretty(pg_catalog.pg_database_size(d.datname))\n"
1004 " ELSE 'No Access'\n"
1006 ",\n t.spcname as \"%s\""
1007 ",\n pg_catalog.shobj_description(d.oid, 'pg_database') as \"%s\"",
1012 "\nFROM pg_catalog.pg_database d\n");
1015 " JOIN pg_catalog.pg_tablespace t on d.dattablespace = t.oid\n");
1020 NULL,
"d.datname", NULL, NULL,
1034 myopt.
title =
_(
"List of databases");
1054 static const bool translate_columns[] = {
false,
false,
true,
false,
false,
false};
1062 "SELECT n.nspname as \"%s\",\n"
1063 " c.relname as \"%s\",\n"
1069 " WHEN " CppAsString2(RELKIND_FOREIGN_TABLE)
" THEN '%s'"
1070 " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE)
" THEN '%s'"
1091 ",\n pg_catalog.array_to_string(ARRAY(\n"
1092 " SELECT attname || E':\\n ' || pg_catalog.array_to_string(attacl, E'\\n ')\n"
1093 " FROM pg_catalog.pg_attribute a\n"
1094 " WHERE attrelid = c.oid AND NOT attisdropped AND attacl IS NOT NULL\n"
1095 " ), E'\\n') AS \"%s\"",
1100 ",\n pg_catalog.array_to_string(ARRAY(\n"
1102 " || CASE WHEN polcmd != '*' THEN\n"
1103 " E' (' || polcmd::pg_catalog.text || E'):'\n"
1106 " || CASE WHEN polqual IS NOT NULL THEN\n"
1107 " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n"
1110 " || CASE WHEN polwithcheck IS NOT NULL THEN\n"
1111 " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n"
1114 " || CASE WHEN polroles <> '{0}' THEN\n"
1115 " E'\\n to: ' || pg_catalog.array_to_string(\n"
1118 " FROM pg_catalog.pg_roles\n"
1119 " WHERE oid = ANY (polroles)\n"
1124 " FROM pg_catalog.pg_policy pol\n"
1125 " WHERE polrelid = c.oid), E'\\n')\n"
1131 ",\n pg_catalog.array_to_string(ARRAY(\n"
1133 " || CASE WHEN NOT polpermissive THEN\n"
1134 " E' (RESTRICTIVE)'\n"
1136 " || CASE WHEN polcmd != '*' THEN\n"
1137 " E' (' || polcmd::pg_catalog.text || E'):'\n"
1140 " || CASE WHEN polqual IS NOT NULL THEN\n"
1141 " E'\\n (u): ' || pg_catalog.pg_get_expr(polqual, polrelid)\n"
1144 " || CASE WHEN polwithcheck IS NOT NULL THEN\n"
1145 " E'\\n (c): ' || pg_catalog.pg_get_expr(polwithcheck, polrelid)\n"
1148 " || CASE WHEN polroles <> '{0}' THEN\n"
1149 " E'\\n to: ' || pg_catalog.array_to_string(\n"
1152 " FROM pg_catalog.pg_roles\n"
1153 " WHERE oid = ANY (polroles)\n"
1158 " FROM pg_catalog.pg_policy pol\n"
1159 " WHERE polrelid = c.oid), E'\\n')\n"
1164 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
1165 "WHERE c.relkind IN ("
1173 if (!showSystem && !pattern)
1175 " AND n.nspname <> 'information_schema'\n");
1178 "n.nspname",
"c.relname", NULL,
1179 "pg_catalog.pg_table_is_visible(c.oid)",
1218 static const bool translate_columns[] = {
false,
false,
true,
false};
1223 "SELECT pg_catalog.pg_get_userbyid(d.defaclrole) AS \"%s\",\n"
1224 " n.nspname AS \"%s\",\n"
1225 " CASE d.defaclobjtype WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' WHEN '%c' THEN '%s' END AS \"%s\",\n"
1237 DEFACLOBJ_NAMESPACE,
1244 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.defaclnamespace\n");
1249 "pg_catalog.pg_get_userbyid(d.defaclrole)",
1295 static const bool translate_columns[] = {
false,
false,
true,
false};
1300 "SELECT DISTINCT tt.nspname AS \"%s\", tt.name AS \"%s\", tt.object AS \"%s\", d.description AS \"%s\"\n"
1309 " SELECT pgc.oid as oid, pgc.tableoid AS tableoid,\n"
1310 " n.nspname as nspname,\n"
1311 " CAST(pgc.conname AS pg_catalog.text) as name,"
1312 " CAST('%s' AS pg_catalog.text) as object\n"
1313 " FROM pg_catalog.pg_constraint pgc\n"
1314 " JOIN pg_catalog.pg_class c "
1315 "ON c.oid = pgc.conrelid\n"
1316 " LEFT JOIN pg_catalog.pg_namespace n "
1317 " ON n.oid = c.relnamespace\n",
1320 if (!showSystem && !pattern)
1322 " AND n.nspname <> 'information_schema'\n");
1325 false,
"n.nspname",
"pgc.conname", NULL,
1326 "pg_catalog.pg_table_is_visible(c.oid)",
1333 " SELECT pgc.oid as oid, pgc.tableoid AS tableoid,\n"
1334 " n.nspname as nspname,\n"
1335 " CAST(pgc.conname AS pg_catalog.text) as name,"
1336 " CAST('%s' AS pg_catalog.text) as object\n"
1337 " FROM pg_catalog.pg_constraint pgc\n"
1338 " JOIN pg_catalog.pg_type t "
1339 "ON t.oid = pgc.contypid\n"
1340 " LEFT JOIN pg_catalog.pg_namespace n "
1341 " ON n.oid = t.typnamespace\n",
1344 if (!showSystem && !pattern)
1346 " AND n.nspname <> 'information_schema'\n");
1349 false,
"n.nspname",
"pgc.conname", NULL,
1350 "pg_catalog.pg_type_is_visible(t.oid)",
1357 " SELECT o.oid as oid, o.tableoid as tableoid,\n"
1358 " n.nspname as nspname,\n"
1359 " CAST(o.opcname AS pg_catalog.text) as name,\n"
1360 " CAST('%s' AS pg_catalog.text) as object\n"
1361 " FROM pg_catalog.pg_opclass o\n"
1362 " JOIN pg_catalog.pg_am am ON "
1363 "o.opcmethod = am.oid\n"
1364 " JOIN pg_catalog.pg_namespace n ON "
1365 "n.oid = o.opcnamespace\n",
1368 if (!showSystem && !pattern)
1370 " AND n.nspname <> 'information_schema'\n");
1373 "n.nspname",
"o.opcname", NULL,
1374 "pg_catalog.pg_opclass_is_visible(o.oid)",
1381 " SELECT opf.oid as oid, opf.tableoid as tableoid,\n"
1382 " n.nspname as nspname,\n"
1383 " CAST(opf.opfname AS pg_catalog.text) AS name,\n"
1384 " CAST('%s' AS pg_catalog.text) as object\n"
1385 " FROM pg_catalog.pg_opfamily opf\n"
1386 " JOIN pg_catalog.pg_am am "
1387 "ON opf.opfmethod = am.oid\n"
1388 " JOIN pg_catalog.pg_namespace n "
1389 "ON opf.opfnamespace = n.oid\n",
1392 if (!showSystem && !pattern)
1394 " AND n.nspname <> 'information_schema'\n");
1397 "n.nspname",
"opf.opfname", NULL,
1398 "pg_catalog.pg_opfamily_is_visible(opf.oid)",
1405 " SELECT r.oid as oid, r.tableoid as tableoid,\n"
1406 " n.nspname as nspname,\n"
1407 " CAST(r.rulename AS pg_catalog.text) as name,"
1408 " CAST('%s' AS pg_catalog.text) as object\n"
1409 " FROM pg_catalog.pg_rewrite r\n"
1410 " JOIN pg_catalog.pg_class c ON c.oid = r.ev_class\n"
1411 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
1412 " WHERE r.rulename != '_RETURN'\n",
1415 if (!showSystem && !pattern)
1417 " AND n.nspname <> 'information_schema'\n");
1420 "n.nspname",
"r.rulename", NULL,
1421 "pg_catalog.pg_table_is_visible(c.oid)",
1428 " SELECT t.oid as oid, t.tableoid as tableoid,\n"
1429 " n.nspname as nspname,\n"
1430 " CAST(t.tgname AS pg_catalog.text) as name,"
1431 " CAST('%s' AS pg_catalog.text) as object\n"
1432 " FROM pg_catalog.pg_trigger t\n"
1433 " JOIN pg_catalog.pg_class c ON c.oid = t.tgrelid\n"
1434 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n",
1437 if (!showSystem && !pattern)
1439 " AND n.nspname <> 'information_schema'\n");
1442 "n.nspname",
"t.tgname", NULL,
1443 "pg_catalog.pg_table_is_visible(c.oid)",
1449 " JOIN pg_catalog.pg_description d ON (tt.oid = d.objoid AND tt.tableoid = d.classoid AND d.objsubid = 0)\n");
1458 myopt.
title =
_(
"Object descriptions");
1495 "FROM pg_catalog.pg_class c\n"
1496 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n");
1498 if (!showSystem && !pattern)
1500 " AND n.nspname <> 'information_schema'\n");
1503 "n.nspname",
"c.relname", NULL,
1504 "pg_catalog.pg_table_is_visible(c.oid)",
1523 pg_log_error(
"Did not find any relation named \"%s\".",
1535 const char *nspname;
1567 const char *relationname,
1571 bool retval =
false;
1576 bool printTableInitialized =
false;
1578 char *view_def = NULL;
1583 int attname_col = -1,
1586 attnotnull_col = -1,
1588 attidentity_col = -1,
1589 attgenerated_col = -1,
1590 isindexkey_col = -1,
1593 attstorage_col = -1,
1594 attcompression_col = -1,
1595 attstattarget_col = -1,
1606 bool forcerowsecurity;
1612 char relpersistence;
1616 bool show_column_details =
false;
1630 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1631 "c.relhastriggers, c.relrowsecurity, c.relforcerowsecurity, "
1632 "false AS relhasoids, c.relispartition, %s, c.reltablespace, "
1633 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
1634 "c.relpersistence, c.relreplident, am.amname\n"
1635 "FROM pg_catalog.pg_class c\n "
1636 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1637 "LEFT JOIN pg_catalog.pg_am am ON (c.relam = am.oid)\n"
1638 "WHERE c.oid = '%s';",
1640 "pg_catalog.array_to_string(c.reloptions || "
1641 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1648 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1649 "c.relhastriggers, c.relrowsecurity, c.relforcerowsecurity, "
1650 "c.relhasoids, c.relispartition, %s, c.reltablespace, "
1651 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
1652 "c.relpersistence, c.relreplident\n"
1653 "FROM pg_catalog.pg_class c\n "
1654 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1655 "WHERE c.oid = '%s';",
1657 "pg_catalog.array_to_string(c.reloptions || "
1658 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1665 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1666 "c.relhastriggers, c.relrowsecurity, c.relforcerowsecurity, "
1667 "c.relhasoids, false as relispartition, %s, c.reltablespace, "
1668 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
1669 "c.relpersistence, c.relreplident\n"
1670 "FROM pg_catalog.pg_class c\n "
1671 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1672 "WHERE c.oid = '%s';",
1674 "pg_catalog.array_to_string(c.reloptions || "
1675 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1682 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1683 "c.relhastriggers, false, false, c.relhasoids, "
1684 "false as relispartition, %s, c.reltablespace, "
1685 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
1686 "c.relpersistence, c.relreplident\n"
1687 "FROM pg_catalog.pg_class c\n "
1688 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1689 "WHERE c.oid = '%s';",
1691 "pg_catalog.array_to_string(c.reloptions || "
1692 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1699 "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
1700 "c.relhastriggers, false, false, c.relhasoids, "
1701 "false as relispartition, %s, c.reltablespace, "
1702 "CASE WHEN c.reloftype = 0 THEN '' ELSE c.reloftype::pg_catalog.regtype::pg_catalog.text END, "
1703 "c.relpersistence\n"
1704 "FROM pg_catalog.pg_class c\n "
1705 "LEFT JOIN pg_catalog.pg_class tc ON (c.reltoastrelid = tc.oid)\n"
1706 "WHERE c.oid = '%s';",
1708 "pg_catalog.array_to_string(c.reloptions || "
1709 "array(select 'toast.' || x from pg_catalog.unnest(tc.reloptions) x), ', ')\n"
1722 pg_log_error(
"Did not find any relation with OID %s.", oid);
1726 tableinfo.checks = atoi(
PQgetvalue(res, 0, 0));
1727 tableinfo.relkind = *(
PQgetvalue(res, 0, 1));
1728 tableinfo.hasindex = strcmp(
PQgetvalue(res, 0, 2),
"t") == 0;
1729 tableinfo.hasrules = strcmp(
PQgetvalue(res, 0, 3),
"t") == 0;
1730 tableinfo.hastriggers = strcmp(
PQgetvalue(res, 0, 4),
"t") == 0;
1731 tableinfo.rowsecurity = strcmp(
PQgetvalue(res, 0, 5),
"t") == 0;
1732 tableinfo.forcerowsecurity = strcmp(
PQgetvalue(res, 0, 6),
"t") == 0;
1733 tableinfo.hasoids = strcmp(
PQgetvalue(res, 0, 7),
"t") == 0;
1734 tableinfo.ispartition = strcmp(
PQgetvalue(res, 0, 8),
"t") == 0;
1737 tableinfo.reloftype = (strcmp(
PQgetvalue(res, 0, 11),
"") != 0) ?
1739 tableinfo.relpersistence = *(
PQgetvalue(res, 0, 12));
1746 tableinfo.relam = NULL;
1753 if (tableinfo.relkind == RELKIND_SEQUENCE)
1757 char *footers[2] = {NULL, NULL};
1762 "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n"
1763 " seqstart AS \"%s\",\n"
1764 " seqmin AS \"%s\",\n"
1765 " seqmax AS \"%s\",\n"
1766 " seqincrement AS \"%s\",\n"
1767 " CASE WHEN seqcycle THEN '%s' ELSE '%s' END AS \"%s\",\n"
1768 " seqcache AS \"%s\"\n",
1779 "FROM pg_catalog.pg_sequence\n"
1780 "WHERE seqrelid = '%s';",
1786 "SELECT 'bigint' AS \"%s\",\n"
1787 " start_value AS \"%s\",\n"
1788 " min_value AS \"%s\",\n"
1789 " max_value AS \"%s\",\n"
1790 " increment_by AS \"%s\",\n"
1791 " CASE WHEN is_cycled THEN '%s' ELSE '%s' END AS \"%s\",\n"
1792 " cache_value AS \"%s\"\n",
1813 "\n pg_catalog.quote_ident(relname) || '.' ||"
1814 "\n pg_catalog.quote_ident(attname),"
1816 "\nFROM pg_catalog.pg_class c"
1817 "\nINNER JOIN pg_catalog.pg_depend d ON c.oid=d.refobjid"
1818 "\nINNER JOIN pg_catalog.pg_namespace n ON n.oid=c.relnamespace"
1819 "\nINNER JOIN pg_catalog.pg_attribute a ON ("
1820 "\n a.attrelid=c.oid AND"
1821 "\n a.attnum=d.refobjsubid)"
1822 "\nWHERE d.classid='pg_catalog.pg_class'::pg_catalog.regclass"
1823 "\n AND d.refclassid='pg_catalog.pg_class'::pg_catalog.regclass"
1824 "\n AND d.objid='%s'"
1825 "\n AND d.deptype IN ('a', 'i')",
1842 footers[0] =
psprintf(
_(
"Owned by: %s"),
1846 footers[0] =
psprintf(
_(
"Sequence for identity column: %s"),
1853 if (tableinfo.relpersistence == RELPERSISTENCE_UNLOGGED)
1855 schemaname, relationname);
1858 schemaname, relationname);
1874 if (tableinfo.relkind == RELKIND_RELATION ||
1875 tableinfo.relkind == RELKIND_VIEW ||
1876 tableinfo.relkind == RELKIND_MATVIEW ||
1877 tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
1878 tableinfo.relkind == RELKIND_COMPOSITE_TYPE ||
1879 tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
1880 show_column_details =
true;
1892 attname_col = cols++;
1894 atttype_col = cols++;
1896 if (show_column_details)
1900 ",\n (SELECT pg_catalog.pg_get_expr(d.adbin, d.adrelid, true)"
1901 "\n FROM pg_catalog.pg_attrdef d"
1902 "\n WHERE d.adrelid = a.attrelid AND d.adnum = a.attnum AND a.atthasdef)"
1903 ",\n a.attnotnull");
1904 attrdef_col = cols++;
1905 attnotnull_col = cols++;
1907 " WHERE c.oid = a.attcollation AND t.oid = a.atttypid AND a.attcollation <> t.typcollation) AS attcollation");
1908 attcoll_col = cols++;
1913 attidentity_col = cols++;
1918 attgenerated_col = cols++;
1920 if (tableinfo.relkind == RELKIND_INDEX ||
1921 tableinfo.relkind == RELKIND_PARTITIONED_INDEX)
1925 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",
1929 isindexkey_col = cols++;
1932 indexdef_col = cols++;
1935 if (tableinfo.relkind == RELKIND_FOREIGN_TABLE)
1938 " '(' || pg_catalog.array_to_string(ARRAY(SELECT pg_catalog.quote_ident(option_name) || ' ' || pg_catalog.quote_literal(option_value) FROM "
1939 " pg_catalog.pg_options_to_table(attfdwoptions)), ', ') || ')' END AS attfdwoptions");
1940 fdwopts_col = cols++;
1945 attstorage_col = cols++;
1950 (tableinfo.relkind == RELKIND_RELATION ||
1951 tableinfo.relkind == RELKIND_PARTITIONED_TABLE ||
1952 tableinfo.relkind == RELKIND_MATVIEW))
1955 attcompression_col = cols++;
1959 if (tableinfo.relkind == RELKIND_RELATION ||
1960 tableinfo.relkind == RELKIND_INDEX ||
1961 tableinfo.relkind == RELKIND_PARTITIONED_INDEX ||
1962 tableinfo.relkind == RELKIND_MATVIEW ||
1963 tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
1964 tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
1966 appendPQExpBufferStr(&
buf,
",\n CASE WHEN a.attstattarget=-1 THEN NULL ELSE a.attstattarget END AS attstattarget");
1967 attstattarget_col = cols++;
1974 if (tableinfo.relkind == RELKIND_RELATION ||
1975 tableinfo.relkind == RELKIND_VIEW ||
1976 tableinfo.relkind == RELKIND_MATVIEW ||
1977 tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
1978 tableinfo.relkind == RELKIND_COMPOSITE_TYPE ||
1979 tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
1982 attdescr_col = cols++;
1987 appendPQExpBuffer(&
buf,
"\nWHERE a.attrelid = '%s' AND a.attnum > 0 AND NOT a.attisdropped", oid);
1996 switch (tableinfo.relkind)
1998 case RELKIND_RELATION:
1999 if (tableinfo.relpersistence == RELPERSISTENCE_UNLOGGED)
2001 schemaname, relationname);
2004 schemaname, relationname);
2008 schemaname, relationname);
2010 case RELKIND_MATVIEW:
2012 schemaname, relationname);
2015 if (tableinfo.relpersistence == RELPERSISTENCE_UNLOGGED)
2017 schemaname, relationname);
2020 schemaname, relationname);
2022 case RELKIND_PARTITIONED_INDEX:
2023 if (tableinfo.relpersistence == RELPERSISTENCE_UNLOGGED)
2025 schemaname, relationname);
2028 schemaname, relationname);
2030 case RELKIND_TOASTVALUE:
2032 schemaname, relationname);
2034 case RELKIND_COMPOSITE_TYPE:
2036 schemaname, relationname);
2038 case RELKIND_FOREIGN_TABLE:
2040 schemaname, relationname);
2042 case RELKIND_PARTITIONED_TABLE:
2043 if (tableinfo.relpersistence == RELPERSISTENCE_UNLOGGED)
2045 schemaname, relationname);
2048 schemaname, relationname);
2053 tableinfo.relkind, schemaname, relationname);
2061 if (show_column_details)
2067 if (isindexkey_col >= 0)
2069 if (indexdef_col >= 0)
2071 if (fdwopts_col >= 0)
2073 if (attstorage_col >= 0)
2075 if (attcompression_col >= 0)
2077 if (attstattarget_col >= 0)
2079 if (attdescr_col >= 0)
2085 printTableInitialized =
true;
2087 for (
i = 0;
i < cols;
i++)
2091 for (
i = 0;
i < numrows;
i++)
2100 if (show_column_details)
2105 bool mustfree =
false;
2110 strcmp(
PQgetvalue(res,
i, attnotnull_col),
"t") == 0 ?
"not null" :
"",
2116 if (identity[0] == ATTRIBUTE_IDENTITY_ALWAYS)
2117 default_str =
"generated always as identity";
2118 else if (identity[0] == ATTRIBUTE_IDENTITY_BY_DEFAULT)
2119 default_str =
"generated by default as identity";
2120 else if (generated[0] == ATTRIBUTE_GENERATED_STORED)
2122 default_str =
psprintf(
"generated always as (%s) stored",
2126 else if (generated[0] == ATTRIBUTE_GENERATED_VIRTUAL)
2128 default_str =
psprintf(
"generated always as (%s)",
2139 if (isindexkey_col >= 0)
2141 if (indexdef_col >= 0)
2145 if (fdwopts_col >= 0)
2149 if (attstorage_col >= 0)
2155 (
storage[0] == TYPSTORAGE_MAIN ?
"main" :
2156 (
storage[0] == TYPSTORAGE_EXTENDED ?
"extended" :
2157 (
storage[0] == TYPSTORAGE_EXTERNAL ?
"external" :
2163 if (attcompression_col >= 0)
2165 char *compression =
PQgetvalue(res,
i, attcompression_col);
2169 (compression[0] ==
'l' ?
"lz4" :
2170 (compression[0] ==
'\0' ?
"" :
2176 if (attstattarget_col >= 0)
2181 if (attdescr_col >= 0)
2188 if (tableinfo.ispartition)
2194 "SELECT inhparent::pg_catalog.regclass,\n"
2195 " pg_catalog.pg_get_expr(c.relpartbound, c.oid),\n ");
2199 "false as inhdetachpending");
2204 ",\n pg_catalog.pg_get_partition_constraintdef(c.oid)");
2206 "\nFROM pg_catalog.pg_class c"
2207 " JOIN pg_catalog.pg_inherits i"
2208 " ON c.oid = inhrelid"
2209 "\nWHERE c.oid = '%s';", oid);
2216 char *parent_name =
PQgetvalue(result, 0, 0);
2222 strcmp(detached,
"t") == 0 ?
" DETACH PENDING" :
"");
2227 char *partconstraintdef = NULL;
2230 partconstraintdef =
PQgetvalue(result, 0, 3);
2232 if (partconstraintdef == NULL || partconstraintdef[0] ==
'\0')
2243 if (tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
2249 "SELECT pg_catalog.pg_get_partkeydef('%s'::pg_catalog.oid);",
2265 if (tableinfo.relkind == RELKIND_TOASTVALUE)
2271 "SELECT n.nspname, c.relname\n"
2272 "FROM pg_catalog.pg_class c"
2273 " JOIN pg_catalog.pg_namespace n"
2274 " ON n.oid = c.relnamespace\n"
2275 "WHERE reltoastrelid = '%s';", oid);
2292 if (tableinfo.relkind == RELKIND_INDEX ||
2293 tableinfo.relkind == RELKIND_PARTITIONED_INDEX)
2299 "SELECT i.indisunique, i.indisprimary, i.indisclustered, "
2301 " (NOT i.indimmediate) AND "
2302 "EXISTS (SELECT 1 FROM pg_catalog.pg_constraint "
2303 "WHERE conrelid = i.indrelid AND "
2304 "conindid = i.indexrelid AND "
2308 "condeferrable) AS condeferrable,\n"
2309 " (NOT i.indimmediate) AND "
2310 "EXISTS (SELECT 1 FROM pg_catalog.pg_constraint "
2311 "WHERE conrelid = i.indrelid AND "
2312 "conindid = i.indexrelid AND "
2316 "condeferred) AS condeferred,\n");
2329 "pg_catalog.pg_get_expr(i.indpred, i.indrelid, true)\n"
2330 "FROM pg_catalog.pg_index i, pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_am a\n"
2331 "WHERE i.indexrelid = c.oid AND c.oid = '%s' AND c.relam = a.oid\n"
2332 "AND i.indrelid = c2.oid;",
2345 char *indisunique =
PQgetvalue(result, 0, 0);
2346 char *indisprimary =
PQgetvalue(result, 0, 1);
2347 char *indisclustered =
PQgetvalue(result, 0, 2);
2351 char *indisreplident =
PQgetvalue(result, 0, 6);
2352 char *indnullsnotdistinct =
PQgetvalue(result, 0, 7);
2357 if (strcmp(indisprimary,
"t") == 0)
2359 else if (strcmp(indisunique,
"t") == 0)
2362 if (strcmp(indnullsnotdistinct,
"t") == 0)
2372 schemaname, indtable);
2374 if (strlen(indpred))
2377 if (strcmp(indisclustered,
"t") == 0)
2380 if (strcmp(indisvalid,
"t") != 0)
2383 if (strcmp(deferrable,
"t") == 0)
2386 if (strcmp(deferred,
"t") == 0)
2389 if (strcmp(indisreplident,
"t") == 0)
2397 if (tableinfo.relkind == RELKIND_INDEX)
2399 tableinfo.tablespace,
true);
2405 else if (tableinfo.relkind == RELKIND_RELATION ||
2406 tableinfo.relkind == RELKIND_MATVIEW ||
2407 tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
2408 tableinfo.relkind == RELKIND_PARTITIONED_TABLE ||
2409 tableinfo.relkind == RELKIND_PARTITIONED_INDEX ||
2410 tableinfo.relkind == RELKIND_TOASTVALUE)
2417 if (tableinfo.hasindex)
2420 "SELECT c2.relname, i.indisprimary, i.indisunique, "
2421 "i.indisclustered, i.indisvalid, "
2422 "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n "
2423 "pg_catalog.pg_get_constraintdef(con.oid, true), "
2424 "contype, condeferrable, condeferred");
2435 "\nFROM pg_catalog.pg_class c, pg_catalog.pg_class c2, pg_catalog.pg_index i\n"
2436 " LEFT JOIN pg_catalog.pg_constraint con ON (conrelid = i.indrelid AND conindid = i.indexrelid AND contype IN ("
2440 "WHERE c.oid = '%s' AND c.oid = i.indrelid AND i.indexrelid = c2.oid\n"
2441 "ORDER BY i.indisprimary DESC, c2.relname;",
2452 for (
i = 0;
i < tuples;
i++)
2470 const char *indexdef;
2471 const char *usingpos;
2476 else if (strcmp(
PQgetvalue(result,
i, 2),
"t") == 0)
2486 usingpos = strstr(indexdef,
" USING ");
2488 indexdef = usingpos + 7;
2521 if (tableinfo.checks)
2524 "SELECT r.conname, "
2525 "pg_catalog.pg_get_constraintdef(r.oid, true)\n"
2526 "FROM pg_catalog.pg_constraint r\n"
2527 "WHERE r.conrelid = '%s' "
2540 for (
i = 0;
i < tuples;
i++)
2558 if (tableinfo.hastriggers ||
2559 tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
2562 (tableinfo.ispartition || tableinfo.relkind == RELKIND_PARTITIONED_TABLE))
2569 "SELECT conrelid = '%s'::pg_catalog.regclass AS sametable,\n"
2571 " pg_catalog.pg_get_constraintdef(oid, true) AS condef,\n"
2572 " conrelid::pg_catalog.regclass AS ontable\n"
2573 " FROM pg_catalog.pg_constraint,\n"
2574 " pg_catalog.pg_partition_ancestors('%s')\n"
2575 " WHERE conrelid = relid AND contype = " CppAsString2(CONSTRAINT_FOREIGN)
" AND conparentid = 0\n"
2576 "ORDER BY sametable DESC, conname;",
2582 "SELECT true as sametable, conname,\n"
2583 " pg_catalog.pg_get_constraintdef(r.oid, true) as condef,\n"
2584 " conrelid::pg_catalog.regclass AS ontable\n"
2585 "FROM pg_catalog.pg_constraint r\n"
2586 "WHERE r.conrelid = '%s' AND r.contype = " CppAsString2(CONSTRAINT_FOREIGN)
"\n",
2602 int i_sametable =
PQfnumber(result,
"sametable"),
2603 i_conname =
PQfnumber(result,
"conname"),
2605 i_ontable =
PQfnumber(result,
"ontable");
2608 for (
i = 0;
i < tuples;
i++)
2615 if (strcmp(
PQgetvalue(result,
i, i_sametable),
"f") == 0)
2632 if (tableinfo.hastriggers ||
2633 tableinfo.relkind == RELKIND_PARTITIONED_TABLE)
2638 "SELECT conname, conrelid::pg_catalog.regclass AS ontable,\n"
2639 " pg_catalog.pg_get_constraintdef(oid, true) AS condef\n"
2640 " FROM pg_catalog.pg_constraint c\n"
2641 " WHERE confrelid IN (SELECT pg_catalog.pg_partition_ancestors('%s')\n"
2642 " UNION ALL VALUES ('%s'::pg_catalog.regclass))\n"
2643 " AND contype = " CppAsString2(CONSTRAINT_FOREIGN)
" AND conparentid = 0\n"
2644 "ORDER BY conname;",
2650 "SELECT conname, conrelid::pg_catalog.regclass AS ontable,\n"
2651 " pg_catalog.pg_get_constraintdef(oid, true) AS condef\n"
2652 " FROM pg_catalog.pg_constraint\n"
2653 " WHERE confrelid = %s AND contype = " CppAsString2(CONSTRAINT_FOREIGN)
"\n"
2654 "ORDER BY conname;",
2666 int i_conname =
PQfnumber(result,
"conname"),
2667 i_ontable =
PQfnumber(result,
"ontable"),
2671 for (
i = 0;
i < tuples;
i++)
2690 " pol.polpermissive,\n");
2693 " 't' as polpermissive,\n");
2695 " 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"
2696 " pg_catalog.pg_get_expr(pol.polqual, pol.polrelid),\n"
2697 " pg_catalog.pg_get_expr(pol.polwithcheck, pol.polrelid),\n"
2698 " CASE pol.polcmd\n"
2699 " WHEN 'r' THEN 'SELECT'\n"
2700 " WHEN 'a' THEN 'INSERT'\n"
2701 " WHEN 'w' THEN 'UPDATE'\n"
2702 " WHEN 'd' THEN 'DELETE'\n"
2704 "FROM pg_catalog.pg_policy pol\n"
2705 "WHERE pol.polrelid = '%s' ORDER BY 1;",
2719 if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples > 0)
2722 if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples > 0)
2725 if (tableinfo.rowsecurity && !tableinfo.forcerowsecurity && tuples == 0)
2728 if (tableinfo.rowsecurity && tableinfo.forcerowsecurity && tuples == 0)
2731 if (!tableinfo.rowsecurity && tuples > 0)
2735 for (
i = 0;
i < tuples;
i++)
2771 "stxrelid::pg_catalog.regclass, "
2772 "stxnamespace::pg_catalog.regnamespace::pg_catalog.text AS nsp, "
2774 "pg_catalog.pg_get_statisticsobjdef_columns(oid) AS columns,\n"
2775 " " CppAsString2(STATS_EXT_NDISTINCT)
" = any(stxkind) AS ndist_enabled,\n"
2776 " " CppAsString2(STATS_EXT_DEPENDENCIES)
" = any(stxkind) AS deps_enabled,\n"
2777 " " CppAsString2(STATS_EXT_MCV)
" = any(stxkind) AS mcv_enabled,\n"
2779 "FROM pg_catalog.pg_statistic_ext\n"
2780 "WHERE stxrelid = '%s'\n"
2781 "ORDER BY nsp, stxname;",
2794 for (
i = 0;
i < tuples;
i++)
2796 bool gotone =
false;
2798 bool has_dependencies;
2803 has_ndistinct = (strcmp(
PQgetvalue(result,
i, 5),
"t") == 0);
2804 has_dependencies = (strcmp(
PQgetvalue(result,
i, 6),
"t") == 0);
2805 has_mcv = (strcmp(
PQgetvalue(result,
i, 7),
"t") == 0);
2822 has_all = (has_ndistinct && has_dependencies && has_mcv);
2823 has_some = (has_ndistinct || has_dependencies || has_mcv);
2825 if (has_some && !has_all)
2836 if (has_dependencies)
2869 "stxrelid::pg_catalog.regclass, "
2870 "stxnamespace::pg_catalog.regnamespace AS nsp, "
2872 " (SELECT pg_catalog.string_agg(pg_catalog.quote_ident(attname),', ')\n"
2873 " FROM pg_catalog.unnest(stxkeys) s(attnum)\n"
2874 " JOIN pg_catalog.pg_attribute a ON (stxrelid = a.attrelid AND\n"
2875 " a.attnum = s.attnum AND NOT attisdropped)) AS columns,\n"
2876 " " CppAsString2(STATS_EXT_NDISTINCT)
" = any(stxkind) AS ndist_enabled,\n"
2877 " " CppAsString2(STATS_EXT_DEPENDENCIES)
" = any(stxkind) AS deps_enabled,\n"
2878 " " CppAsString2(STATS_EXT_MCV)
" = any(stxkind) AS mcv_enabled,\n");
2885 "WHERE stxrelid = '%s'\n"
2899 for (
i = 0;
i < tuples;
i++)
2901 bool gotone =
false;
2944 if (tableinfo.hasrules && tableinfo.relkind != RELKIND_MATVIEW)
2947 "SELECT r.rulename, trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true)), "
2949 "FROM pg_catalog.pg_rewrite r\n"
2950 "WHERE r.ev_class = '%s' ORDER BY 1;",
2963 for (category = 0; category < 4; category++)
2965 have_heading =
false;
2967 for (
i = 0;
i < tuples;
i++)
2969 const char *ruledef;
2970 bool list_rule =
false;
3012 have_heading =
true;
3035 "FROM pg_catalog.pg_publication p\n"
3036 " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n"
3037 " JOIN pg_catalog.pg_class pc ON pc.relnamespace = pn.pnnspid\n"
3038 "WHERE pc.oid ='%s' and pg_catalog.pg_relation_is_publishable('%s')\n"
3041 " , pg_get_expr(pr.prqual, c.oid)\n"
3042 " , (CASE WHEN pr.prattrs IS NOT NULL THEN\n"
3043 " (SELECT string_agg(attname, ', ')\n"
3044 " FROM pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n"
3045 " pg_catalog.pg_attribute\n"
3046 " WHERE attrelid = pr.prrelid AND attnum = prattrs[s])\n"
3048 "FROM pg_catalog.pg_publication p\n"
3049 " JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n"
3050 " JOIN pg_catalog.pg_class c ON c.oid = pr.prrelid\n"
3051 "WHERE pr.prrelid = '%s'\n"
3056 "FROM pg_catalog.pg_publication p\n"
3057 "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n"
3059 oid, oid, oid, oid);
3067 "FROM pg_catalog.pg_publication p\n"
3068 "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n"
3069 "WHERE pr.prrelid = '%s'\n"
3074 "FROM pg_catalog.pg_publication p\n"
3075 "WHERE p.puballtables AND pg_catalog.pg_relation_is_publishable('%s')\n"
3090 for (
i = 0;
i < tuples;
i++)
3116 "SELECT c.conname, a.attname, c.connoinherit,\n"
3117 " c.conislocal, c.coninhcount <> 0\n"
3118 "FROM pg_catalog.pg_constraint c JOIN\n"
3119 " pg_catalog.pg_attribute a ON\n"
3120 " (a.attrelid = c.conrelid AND a.attnum = c.conkey[1])\n"
3121 "WHERE c.contype = " CppAsString2(CONSTRAINT_NOTNULL)
" AND\n"
3122 " c.conrelid = '%s'::pg_catalog.regclass\n"
3123 "ORDER BY a.attnum",
3136 for (
i = 0;
i < tuples;
i++)
3138 bool islocal =
PQgetvalue(result,
i, 3)[0] ==
't';
3139 bool inherited =
PQgetvalue(result,
i, 4)[0] ==
't';
3146 islocal && inherited ?
_(
" (local, inherited)") :
3147 inherited ?
_(
" (inherited)") :
"");
3156 if ((tableinfo.relkind == RELKIND_VIEW ||
3157 tableinfo.relkind == RELKIND_MATVIEW) &&
verbose)
3162 "SELECT pg_catalog.pg_get_viewdef('%s'::pg_catalog.oid, true);",
3183 if (tableinfo.hasrules)
3186 "SELECT r.rulename, trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true))\n"
3187 "FROM pg_catalog.pg_rewrite r\n"
3188 "WHERE r.ev_class = '%s' AND r.rulename != '_RETURN' ORDER BY 1;",
3199 const char *ruledef;
3217 if (tableinfo.hastriggers)
3224 "pg_catalog.pg_get_triggerdef(t.oid, true), "
3225 "t.tgenabled, t.tgisinternal,\n");
3243 " CASE WHEN t.tgparentid != 0 THEN\n"
3244 " (SELECT u.tgrelid::pg_catalog.regclass\n"
3245 " FROM pg_catalog.pg_trigger AS u,\n"
3246 " pg_catalog.pg_partition_ancestors(t.tgrelid) WITH ORDINALITY AS a(relid, depth)\n"
3247 " WHERE u.tgname = t.tgname AND u.tgrelid = a.relid\n"
3248 " AND u.tgparentid = 0\n"
3249 " ORDER BY a.depth LIMIT 1)\n"
3250 " END AS parent\n");
3255 "FROM pg_catalog.pg_trigger t\n"
3256 "WHERE t.tgrelid = '%s' AND ",
3268 " OR EXISTS (SELECT 1 FROM pg_catalog.pg_depend WHERE objid = t.oid \n"
3269 " AND refclassid = 'pg_catalog.pg_trigger'::pg_catalog.regclass))");
3291 for (category = 0; category <= 4; category++)
3293 have_heading =
false;
3294 for (
i = 0;
i < tuples;
i++)
3298 const char *usingpos;
3299 const char *tgenabled;
3300 const char *tgisinternal;
3307 list_trigger =
false;
3311 if (*tgenabled ==
'O' || *tgenabled ==
't')
3312 list_trigger =
true;
3315 if ((*tgenabled ==
'D' || *tgenabled ==
'f') &&
3316 *tgisinternal ==
'f')
3317 list_trigger =
true;
3320 if ((*tgenabled ==
'D' || *tgenabled ==
'f') &&
3321 *tgisinternal ==
't')
3322 list_trigger =
true;
3325 if (*tgenabled ==
'A')
3326 list_trigger =
true;
3329 if (*tgenabled ==
'R')
3330 list_trigger =
true;
3333 if (list_trigger ==
false)
3337 if (have_heading ==
false)
3358 have_heading =
true;
3363 usingpos = strstr(tgdef,
" TRIGGER ");
3365 tgdef = usingpos + 9;
3384 if (tableinfo.relkind == RELKIND_RELATION ||
3385 tableinfo.relkind == RELKIND_MATVIEW ||
3386 tableinfo.relkind == RELKIND_FOREIGN_TABLE ||
3387 tableinfo.relkind == RELKIND_PARTITIONED_TABLE ||
3388 tableinfo.relkind == RELKIND_PARTITIONED_INDEX ||
3389 tableinfo.relkind == RELKIND_TOASTVALUE)
3391 bool is_partitioned;
3396 is_partitioned = (tableinfo.relkind == RELKIND_PARTITIONED_TABLE ||
3397 tableinfo.relkind == RELKIND_PARTITIONED_INDEX);
3400 if (tableinfo.relkind == RELKIND_FOREIGN_TABLE)
3406 "SELECT s.srvname,\n"
3407 " pg_catalog.array_to_string(ARRAY(\n"
3408 " SELECT pg_catalog.quote_ident(option_name)"
3409 " || ' ' || pg_catalog.quote_literal(option_value)\n"
3410 " FROM pg_catalog.pg_options_to_table(ftoptions)), ', ')\n"
3411 "FROM pg_catalog.pg_foreign_table f,\n"
3412 " pg_catalog.pg_foreign_server s\n"
3413 "WHERE f.ftrelid = '%s' AND s.oid = f.ftserver;",
3431 if (ftoptions && ftoptions[0] !=
'\0')
3441 "SELECT c.oid::pg_catalog.regclass\n"
3442 "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n"
3443 "WHERE c.oid = i.inhparent AND i.inhrelid = '%s'\n"
3444 " AND c.relkind != " CppAsString2(RELKIND_PARTITIONED_TABLE)
3445 " AND c.relkind != " CppAsString2(RELKIND_PARTITIONED_INDEX)
3446 "\nORDER BY inhseqno;",
3454 const char *s =
_(
"Inherits");
3459 for (
i = 0;
i < tuples;
i++)
3479 "SELECT c.oid::pg_catalog.regclass, c.relkind,"
3480 " inhdetachpending,"
3481 " pg_catalog.pg_get_expr(c.relpartbound, c.oid)\n"
3482 "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n"
3483 "WHERE c.oid = i.inhrelid AND i.inhparent = '%s'\n"
3484 "ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT',"
3485 " c.oid::pg_catalog.regclass::pg_catalog.text;",
3489 "SELECT c.oid::pg_catalog.regclass, c.relkind,"
3490 " false AS inhdetachpending,"
3491 " pg_catalog.pg_get_expr(c.relpartbound, c.oid)\n"
3492 "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n"
3493 "WHERE c.oid = i.inhrelid AND i.inhparent = '%s'\n"
3494 "ORDER BY pg_catalog.pg_get_expr(c.relpartbound, c.oid) = 'DEFAULT',"
3495 " c.oid::pg_catalog.regclass::pg_catalog.text;",
3499 "SELECT c.oid::pg_catalog.regclass, c.relkind,"
3500 " false AS inhdetachpending, NULL\n"
3501 "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n"
3502 "WHERE c.oid = i.inhrelid AND i.inhparent = '%s'\n"
3503 "ORDER BY c.oid::pg_catalog.regclass::pg_catalog.text;",
3517 if (is_partitioned && tuples == 0)
3537 const char *ct = is_partitioned ?
_(
"Partitions") :
_(
"Child tables");
3540 for (
i = 0;
i < tuples;
i++)
3552 if (child_relkind == RELKIND_PARTITIONED_TABLE ||
3553 child_relkind == RELKIND_PARTITIONED_INDEX)
3555 else if (child_relkind == RELKIND_FOREIGN_TABLE)
3568 if (tableinfo.reloftype)
3575 (tableinfo.relkind == RELKIND_RELATION ||
3576 tableinfo.relkind == RELKIND_MATVIEW) &&
3582 tableinfo.relreplident != REPLICA_IDENTITY_INDEX &&
3583 ((strcmp(schemaname,
"pg_catalog") != 0 &&
3584 tableinfo.relreplident != REPLICA_IDENTITY_DEFAULT) ||
3585 (strcmp(schemaname,
"pg_catalog") == 0 &&
3586 tableinfo.relreplident != REPLICA_IDENTITY_NOTHING)))
3588 const char *s =
_(
"Replica Identity");
3592 tableinfo.relreplident == REPLICA_IDENTITY_FULL ?
"FULL" :
3593 tableinfo.relreplident == REPLICA_IDENTITY_DEFAULT ?
"NOTHING" :
3600 if (
verbose && tableinfo.relkind != RELKIND_MATVIEW && tableinfo.hasoids)
3617 tableinfo.reloptions && tableinfo.reloptions[0] !=
'\0')
3619 const char *t =
_(
"Options");
3632 if (printTableInitialized)
3655 if (relkind == RELKIND_RELATION ||
3656 relkind == RELKIND_MATVIEW ||
3657 relkind == RELKIND_INDEX ||
3658 relkind == RELKIND_PARTITIONED_TABLE ||
3659 relkind == RELKIND_PARTITIONED_INDEX ||
3660 relkind == RELKIND_TOASTVALUE)
3673 "SELECT spcname FROM pg_catalog.pg_tablespace\n"
3726 const char align =
'l';
3734 "SELECT r.rolname, r.rolsuper, r.rolinherit,\n"
3735 " r.rolcreaterole, r.rolcreatedb, r.rolcanlogin,\n"
3736 " r.rolconnlimit, r.rolvaliduntil");
3752 if (!showSystem && !pattern)
3756 NULL,
"r.rolname", NULL, NULL,
3770 attr =
pg_malloc0((nrows + 1) *
sizeof(*attr));
3780 for (
i = 0;
i < nrows;
i++)
3842 for (
i = 0;
i < nrows;
i++)
3873 "pg_catalog.array_to_string(setconfig, E'\\n') AS \"%s\"\n"
3874 "FROM pg_catalog.pg_db_role_setting s\n"
3875 "LEFT JOIN pg_catalog.pg_database d ON d.oid = setdatabase\n"
3876 "LEFT JOIN pg_catalog.pg_roles r ON r.oid = setrole\n",
3881 NULL,
"r.rolname", NULL, NULL, &havewhere, 1))
3884 NULL,
"d.datname", NULL, NULL,
3902 if (pattern && pattern2)
3903 pg_log_error(
"Did not find any settings for role \"%s\" and database \"%s\".",
3906 pg_log_error(
"Did not find any settings for role \"%s\".",
3913 myopt.
title =
_(
"List of settings");
3940 "SELECT m.rolname AS \"%s\", r.rolname AS \"%s\",\n"
3941 " pg_catalog.concat_ws(', ',\n",
3947 " CASE WHEN pam.admin_option THEN 'ADMIN' END,\n"
3948 " CASE WHEN pam.inherit_option THEN 'INHERIT' END,\n"
3949 " CASE WHEN pam.set_option THEN 'SET' END\n");
3952 " CASE WHEN pam.admin_option THEN 'ADMIN' END,\n"
3953 " CASE WHEN m.rolinherit THEN 'INHERIT' END,\n"
3958 " g.rolname AS \"%s\"\n",
3963 "FROM pg_catalog.pg_roles m\n"
3964 " JOIN pg_catalog.pg_auth_members pam ON (pam.member = m.oid)\n"
3965 " LEFT JOIN pg_catalog.pg_roles r ON (pam.roleid = r.oid)\n"
3966 " LEFT JOIN pg_catalog.pg_roles g ON (pam.grantor = g.oid)\n");
3968 if (!showSystem && !pattern)
3972 NULL,
"m.rolname", NULL, NULL,
3986 myopt.
title =
_(
"List of role grants");
4013 bool showTables = strchr(tabtypes,
't') != NULL;
4014 bool showIndexes = strchr(tabtypes,
'i') != NULL;
4015 bool showViews = strchr(tabtypes,
'v') != NULL;
4016 bool showMatViews = strchr(tabtypes,
'm') != NULL;
4017 bool showSeq = strchr(tabtypes,
's') != NULL;
4018 bool showForeign = strchr(tabtypes,
'E') != NULL;
4025 bool translate_columns[] = {
false,
false,
true,
false,
false,
false,
false,
false,
false};
4028 ntypes = showTables + showIndexes + showViews + showMatViews +
4029 showSeq + showForeign;
4032 showTables = showViews = showMatViews = showSeq = showForeign =
true;
4037 "SELECT n.nspname as \"%s\",\n"
4038 " c.relname as \"%s\",\n"
4046 " WHEN " CppAsString2(RELKIND_FOREIGN_TABLE)
" THEN '%s'"
4047 " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE)
" THEN '%s'"
4048 " WHEN " CppAsString2(RELKIND_PARTITIONED_INDEX)
" THEN '%s'"
4050 " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
4069 ",\n c2.relname as \"%s\"",
4080 ",\n CASE c.relpersistence "
4081 "WHEN " CppAsString2(RELPERSISTENCE_PERMANENT)
" THEN '%s' "
4082 "WHEN " CppAsString2(RELPERSISTENCE_TEMP)
" THEN '%s' "
4083 "WHEN " CppAsString2(RELPERSISTENCE_UNLOGGED)
" THEN '%s' "
4089 translate_columns[cols_so_far] =
true;
4101 (showTables || showMatViews || showIndexes))
4103 ",\n am.amname as \"%s\"",
4107 ",\n pg_catalog.pg_size_pretty(pg_catalog.pg_table_size(c.oid)) as \"%s\""
4108 ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
4114 "\nFROM pg_catalog.pg_class c"
4115 "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
4118 (showTables || showMatViews || showIndexes))
4120 "\n LEFT JOIN pg_catalog.pg_am am ON am.oid = c.relam");
4124 "\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
4125 "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
4133 if (showSystem || pattern)
4145 if (showSystem || pattern)
4153 if (!showSystem && !pattern)
4155 " AND n.nspname !~ '^pg_toast'\n"
4156 " AND n.nspname <> 'information_schema'\n");
4159 "n.nspname",
"c.relname", NULL,
4160 "pg_catalog.pg_table_is_visible(c.oid)",
4184 pg_log_error(
"Did not find any relations named \"%s\".",
4186 else if (showTables)
4189 else if (showIndexes)
4195 else if (showMatViews)
4196 pg_log_error(
"Did not find any materialized views named \"%s\".",
4199 pg_log_error(
"Did not find any sequences named \"%s\".",
4201 else if (showForeign)
4202 pg_log_error(
"Did not find any foreign tables named \"%s\".",
4212 else if (showTables)
4214 else if (showIndexes)
4218 else if (showMatViews)
4222 else if (showForeign)
4231 (ntypes != 1) ?
_(
"List of relations") :
4232 (showTables) ?
_(
"List of tables") :
4233 (showIndexes) ?
_(
"List of indexes") :
4234 (showViews) ?
_(
"List of views") :
4235 (showMatViews) ?
_(
"List of materialized views") :
4236 (showSeq) ?
_(
"List of sequences") :
4237 (showForeign) ?
_(
"List of foreign tables") :
4268 bool showTables = strchr(reltypes,
't') != NULL;
4269 bool showIndexes = strchr(reltypes,
'i') != NULL;
4270 bool showNested = strchr(reltypes,
'n') != NULL;
4275 bool translate_columns[] = {
false,
false,
false,
false,
false,
false,
false,
false,
false,
false};
4276 const char *tabletitle;
4277 bool mixed_output =
false;
4286 pg_log_error(
"The server (version %s) does not support declarative table partitioning.",
4288 sverbuf,
sizeof(sverbuf)));
4293 if (!showTables && !showIndexes)
4294 showTables = showIndexes =
true;
4296 if (showIndexes && !showTables)
4297 tabletitle =
_(
"List of partitioned indexes");
4298 else if (showTables && !showIndexes)
4299 tabletitle =
_(
"List of partitioned tables");
4303 tabletitle =
_(
"List of partitioned relations");
4304 mixed_output =
true;
4310 "SELECT n.nspname as \"%s\",\n"
4311 " c.relname as \"%s\",\n"
4312 " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
4320 ",\n CASE c.relkind"
4321 " WHEN " CppAsString2(RELKIND_PARTITIONED_TABLE)
" THEN '%s'"
4322 " WHEN " CppAsString2(RELKIND_PARTITIONED_INDEX)
" THEN '%s'"
4328 translate_columns[3] =
true;
4331 if (showNested || pattern)
4333 ",\n inh.inhparent::pg_catalog.regclass as \"%s\"",
4338 ",\n c2.oid::pg_catalog.regclass as \"%s\"",
4353 ",\n s.dps as \"%s\"",
4356 ",\n s.tps as \"%s\"",
4362 ",\n s.tps as \"%s\"",
4366 ",\n pg_catalog.obj_description(c.oid, 'pg_class') as \"%s\"",
4371 "\nFROM pg_catalog.pg_class c"
4372 "\n LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace");
4376 "\n LEFT JOIN pg_catalog.pg_index i ON i.indexrelid = c.oid"
4377 "\n LEFT JOIN pg_catalog.pg_class c2 ON i.indrelid = c2.oid");
4379 if (showNested || pattern)
4381 "\n LEFT JOIN pg_catalog.pg_inherits inh ON c.oid = inh.inhrelid");
4386 "\n LEFT JOIN pg_catalog.pg_am am ON c.relam = am.oid");
4391 ",\n LATERAL (WITH RECURSIVE d\n"
4392 " AS (SELECT inhrelid AS oid, 1 AS level\n"
4393 " FROM pg_catalog.pg_inherits\n"
4394 " WHERE inhparent = c.oid\n"
4396 " SELECT inhrelid, level + 1\n"
4397 " FROM pg_catalog.pg_inherits i\n"
4398 " JOIN d ON i.inhparent = d.oid)\n"
4399 " SELECT pg_catalog.pg_size_pretty(sum(pg_catalog.pg_table_size("
4400 "d.oid))) AS tps,\n"
4401 " pg_catalog.pg_size_pretty(sum("
4402 "\n CASE WHEN d.level = 1"
4403 " THEN pg_catalog.pg_table_size(d.oid) ELSE 0 END)) AS dps\n"
4410 ",\n LATERAL (SELECT pg_catalog.pg_size_pretty(sum("
4411 "\n CASE WHEN ppt.isleaf AND ppt.level = 1"
4412 "\n THEN pg_catalog.pg_table_size(ppt.relid)"
4413 " ELSE 0 END)) AS dps"
4414 ",\n pg_catalog.pg_size_pretty(sum("
4415 "pg_catalog.pg_table_size(ppt.relid))) AS tps"
4416 "\n FROM pg_catalog.pg_partition_tree(c.oid) ppt) s");
4429 " AND NOT c.relispartition\n" :
"");
4433 " AND n.nspname !~ '^pg_toast'\n"
4434 " AND n.nspname <> 'information_schema'\n");
4437 "n.nspname",
"c.relname", NULL,
4438 "pg_catalog.pg_table_is_visible(c.oid)",
4446 mixed_output ?
"\"Type\" DESC, " :
"",
4447 showNested || pattern ?
"\"Parent name\" NULLS FIRST, " :
"");
4485 "SELECT l.lanname AS \"%s\",\n"
4486 " pg_catalog.pg_get_userbyid(l.lanowner) as \"%s\",\n"
4487 " l.lanpltrusted AS \"%s\"",
4495 ",\n NOT l.lanispl AS \"%s\",\n"
4496 " l.lanplcallfoid::pg_catalog.regprocedure AS \"%s\",\n"
4497 " l.lanvalidator::pg_catalog.regprocedure AS \"%s\",\n "
4498 "l.laninline::pg_catalog.regprocedure AS \"%s\",\n ",
4507 ",\n d.description AS \"%s\""
4508 "\nFROM pg_catalog.pg_language l\n"
4509 "LEFT JOIN pg_catalog.pg_description d\n"
4510 " ON d.classoid = l.tableoid AND d.objoid = l.oid\n"
4511 " AND d.objsubid = 0\n",
4517 NULL,
"l.lanname", NULL, NULL,
4525 if (!showSystem && !pattern)
4536 myopt.
title =
_(
"List of languages");
4561 "SELECT n.nspname as \"%s\",\n"
4562 " t.typname as \"%s\",\n"
4563 " pg_catalog.format_type(t.typbasetype, t.typtypmod) as \"%s\",\n"
4564 " (SELECT c.collname FROM pg_catalog.pg_collation c, pg_catalog.pg_type bt\n"
4565 " WHERE c.oid = t.typcollation AND bt.oid = t.typbasetype AND t.typcollation <> bt.typcollation) as \"%s\",\n"
4566 " CASE WHEN t.typnotnull THEN 'not null' END as \"%s\",\n"
4567 " t.typdefault as \"%s\",\n"
4568 " pg_catalog.array_to_string(ARRAY(\n"
4569 " 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"
4570 " ), ' ') as \"%s\"",
4584 ",\n d.description as \"%s\"",
4589 "\nFROM pg_catalog.pg_type t\n"
4590 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.typnamespace\n");
4594 " LEFT JOIN pg_catalog.pg_description d "
4595 "ON d.classoid = t.tableoid AND d.objoid = t.oid "
4596 "AND d.objsubid = 0\n");
4600 if (!showSystem && !pattern)
4602 " AND n.nspname <> 'information_schema'\n");
4605 "n.nspname",
"t.typname", NULL,
4606 "pg_catalog.pg_type_is_visible(t.oid)",
4620 myopt.
title =
_(
"List of domains");
4640 static const bool translate_columns[] =
4641 {
false,
false,
false,
false,
true,
false};
4646 "SELECT n.nspname AS \"%s\",\n"
4647 " c.conname AS \"%s\",\n"
4648 " pg_catalog.pg_encoding_to_char(c.conforencoding) AS \"%s\",\n"
4649 " pg_catalog.pg_encoding_to_char(c.contoencoding) AS \"%s\",\n"
4650 " CASE WHEN c.condefault THEN '%s'\n"
4651 " ELSE '%s' END AS \"%s\"",
4661 ",\n d.description AS \"%s\"",
4665 "\nFROM pg_catalog.pg_conversion c\n"
4666 " JOIN pg_catalog.pg_namespace n "
4667 "ON n.oid = c.connamespace\n");
4671 "LEFT JOIN pg_catalog.pg_description d "
4672 "ON d.classoid = c.tableoid\n"
4673 " AND d.objoid = c.oid "
4674 "AND d.objsubid = 0\n");
4678 if (!showSystem && !pattern)
4680 " AND n.nspname <> 'information_schema'\n");
4683 "n.nspname",
"c.conname", NULL,
4684 "pg_catalog.pg_conversion_is_visible(c.oid)",
4698 myopt.
title =
_(
"List of conversions");
4724 "SELECT s.name AS \"%s\", "
4725 "pg_catalog.current_setting(s.name) AS \"%s\"",
4732 ", s.vartype AS \"%s\", s.context AS \"%s\", ",
4746 " LEFT JOIN pg_catalog.pg_parameter_acl p\n"
4747 " ON pg_catalog.lower(s.name) = p.parname\n");
4752 NULL,
"pg_catalog.lower(s.name)", NULL,
4756 " s.setting IS DISTINCT FROM s.boot_val\n");
4766 myopt.
title =
_(
"List of configuration parameters");
4768 myopt.
title =
_(
"List of non-default configuration parameters");
4788 static const bool translate_columns[] =
4789 {
false,
false,
false,
true,
false,
false,
false};
4795 pg_log_error(
"The server (version %s) does not support event triggers.",
4797 sverbuf,
sizeof(sverbuf)));
4804 "SELECT evtname as \"%s\", "
4805 "evtevent as \"%s\", "
4806 "pg_catalog.pg_get_userbyid(e.evtowner) as \"%s\",\n"
4807 " case evtenabled when 'O' then '%s'"
4808 " when 'R' then '%s'"
4809 " when 'A' then '%s'"
4810 " when 'D' then '%s' end as \"%s\",\n"
4811 " e.evtfoid::pg_catalog.regproc as \"%s\", "
4812 "pg_catalog.array_to_string(array(select x"
4813 " from pg_catalog.unnest(evttags) as t(x)), ', ') as \"%s\"",
4826 ",\npg_catalog.obj_description(e.oid, 'pg_event_trigger') as \"%s\"",
4829 "\nFROM pg_catalog.pg_event_trigger e ");
4832 NULL,
"evtname", NULL, NULL,
4846 myopt.
title =
_(
"List of event triggers");
4873 pg_log_error(
"The server (version %s) does not support extended statistics.",
4875 sverbuf,
sizeof(sverbuf)));
4882 "es.stxnamespace::pg_catalog.regnamespace::pg_catalog.text AS \"%s\", \n"
4883 "es.stxname AS \"%s\", \n",
4889 "pg_catalog.format('%%s FROM %%s', \n"
4890 " pg_catalog.pg_get_statisticsobjdef_columns(es.oid), \n"
4891 " es.stxrelid::pg_catalog.regclass) AS \"%s\"",
4895 "pg_catalog.format('%%s FROM %%s', \n"
4896 " (SELECT pg_catalog.string_agg(pg_catalog.quote_ident(a.attname),', ') \n"
4897 " FROM pg_catalog.unnest(es.stxkeys) s(attnum) \n"
4898 " JOIN pg_catalog.pg_attribute a \n"
4899 " ON (es.stxrelid = a.attrelid \n"
4900 " AND a.attnum = s.attnum \n"
4901 " AND NOT a.attisdropped)), \n"
4902 "es.stxrelid::pg_catalog.regclass) AS \"%s\"",
4906 ",\nCASE WHEN " CppAsString2(STATS_EXT_NDISTINCT)
" = any(es.stxkind) THEN 'defined' \n"
4908 "CASE WHEN " CppAsString2(STATS_EXT_DEPENDENCIES)
" = any(es.stxkind) THEN 'defined' \n"
4919 ",\nCASE WHEN " CppAsString2(STATS_EXT_MCV)
" = any(es.stxkind) THEN 'defined' \n"
4925 " \nFROM pg_catalog.pg_statistic_ext es \n");
4929 "es.stxnamespace::pg_catalog.regnamespace::pg_catalog.text",
"es.stxname",
4930 NULL,
"pg_catalog.pg_statistics_obj_is_visible(es.oid)",
4944 myopt.
title =
_(
"List of extended statistics");
4964 static const bool translate_columns[] = {
false,
false,
false,
true,
true,
false};
4969 "SELECT pg_catalog.format_type(castsource, NULL) AS \"%s\",\n"
4970 " pg_catalog.format_type(casttarget, NULL) AS \"%s\",\n",
4980 " CASE WHEN c.castmethod = '%c' THEN '(binary coercible)'\n"
4981 " WHEN c.castmethod = '%c' THEN '(with inout)'\n"
4983 " END AS \"%s\",\n",
4984 COERCION_METHOD_BINARY,
4985 COERCION_METHOD_INOUT,
4989 " CASE WHEN c.castcontext = '%c' THEN '%s'\n"
4990 " WHEN c.castcontext = '%c' THEN '%s'\n"
4993 COERCION_CODE_EXPLICIT,
4995 COERCION_CODE_ASSIGNMENT,
5002 ",\n CASE WHEN p.proleakproof THEN '%s'\n"
5005 " d.description AS \"%s\"",
5016 "\nFROM pg_catalog.pg_cast c LEFT JOIN pg_catalog.pg_proc p\n"
5017 " ON c.castfunc = p.oid\n"
5018 " LEFT JOIN pg_catalog.pg_type ts\n"
5019 " ON c.castsource = ts.oid\n"
5020 " LEFT JOIN pg_catalog.pg_namespace ns\n"
5021 " ON ns.oid = ts.typnamespace\n"
5022 " LEFT JOIN pg_catalog.pg_type tt\n"
5023 " ON c.casttarget = tt.oid\n"
5024 " LEFT JOIN pg_catalog.pg_namespace nt\n"
5025 " ON nt.oid = tt.typnamespace\n");
5029 " LEFT JOIN pg_catalog.pg_description d\n"
5030 " ON d.classoid = c.tableoid AND d.objoid = "
5031 "c.oid AND d.objsubid = 0\n");
5040 "ns.nspname",
"ts.typname",
5041 "pg_catalog.format_type(ts.oid, NULL)",
5042 "pg_catalog.pg_type_is_visible(ts.oid)",
5049 "nt.nspname",
"tt.typname",
5050 "pg_catalog.format_type(tt.oid, NULL)",
5051 "pg_catalog.pg_type_is_visible(tt.oid)",
5062 myopt.
title =
_(
"List of casts");
5088 static const bool translate_columns[] = {
false,
false,
false,
false,
false,
false,
false,
true,
false};
5094 " n.nspname AS \"%s\",\n"
5095 " c.collname AS \"%s\",\n",
5101 " CASE c.collprovider "
5102 "WHEN " CppAsString2(COLLPROVIDER_DEFAULT)
" THEN 'default' "
5103 "WHEN " CppAsString2(COLLPROVIDER_BUILTIN)
" THEN 'builtin' "
5104 "WHEN " CppAsString2(COLLPROVIDER_LIBC)
" THEN 'libc' "
5110 " 'libc' AS \"%s\",\n",
5114 " c.collcollate AS \"%s\",\n"
5115 " c.collctype AS \"%s\",\n",
5121 " c.colllocale AS \"%s\",\n",
5125 " c.colliculocale AS \"%s\",\n",
5129 " c.collcollate AS \"%s\",\n",
5134 " c.collicurules AS \"%s\",\n",
5138 " NULL AS \"%s\",\n",
5143 " CASE WHEN c.collisdeterministic THEN '%s' ELSE '%s' END AS \"%s\"",
5154 ",\n pg_catalog.obj_description(c.oid, 'pg_collation') AS \"%s\"",
5158 "\nFROM pg_catalog.pg_collation c, pg_catalog.pg_namespace n\n"
5159 "WHERE n.oid = c.collnamespace\n");
5161 if (!showSystem && !pattern)
5163 " AND n.nspname <> 'information_schema'\n");
5171 appendPQExpBufferStr(&
buf,
" AND c.collencoding IN (-1, pg_catalog.pg_char_to_encoding(pg_catalog.getdatabaseencoding()))\n");
5174 "n.nspname",
"c.collname", NULL,
5175 "pg_catalog.pg_collation_is_visible(c.oid)",
5189 myopt.
title =
_(
"List of collations");
5211 int pub_schema_tuples = 0;
5212 char **footers = NULL;
5216 "SELECT n.nspname AS \"%s\",\n"
5217 " pg_catalog.pg_get_userbyid(n.nspowner) AS \"%s\"",
5226 ",\n pg_catalog.obj_description(n.oid, 'pg_namespace') AS \"%s\"",
5231 "\nFROM pg_catalog.pg_namespace n\n");
5233 if (!showSystem && !pattern)
5235 "WHERE n.nspname !~ '^pg_' AND n.nspname <> 'information_schema'\n");
5238 !showSystem && !pattern,
false,
5239 NULL,
"n.nspname", NULL,
5250 myopt.
title =
_(
"List of schemas");
5260 "FROM pg_catalog.pg_publication p\n"
5261 " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n"
5262 " JOIN pg_catalog.pg_namespace n ON n.oid = pn.pnnspid \n"
5263 "WHERE n.nspname = '%s'\n"
5272 if (pub_schema_tuples > 0)
5279 footers = (
char **)
pg_malloc((1 + pub_schema_tuples + 1) *
sizeof(
char *));
5283 for (
i = 0;
i < pub_schema_tuples;
i++)
5291 footers[
i + 1] = NULL;
5306 char **footer = NULL;
5308 for (footer = footers; *footer; footer++)
5340 " n.nspname as \"%s\",\n"
5341 " p.prsname as \"%s\",\n"
5342 " pg_catalog.obj_description(p.oid, 'pg_ts_parser') as \"%s\"\n"
5343 "FROM pg_catalog.pg_ts_parser p\n"
5344 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.prsnamespace\n",
5351 "n.nspname",
"p.prsname", NULL,
5352 "pg_catalog.pg_ts_parser_is_visible(p.oid)",
5366 myopt.
title =
_(
"List of text search parsers");
5391 "FROM pg_catalog.pg_ts_parser p\n"
5392 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = p.prsnamespace\n"
5396 "n.nspname",
"p.prsname", NULL,
5397 "pg_catalog.pg_ts_parser_is_visible(p.oid)",
5416 pg_log_error(
"Did not find any text search parser named \"%s\".",
5428 const char *nspname = NULL;
5429 const char *prsname;
5460 static const bool translate_columns[] = {
true,
false,
false};
5465 "SELECT '%s' AS \"%s\",\n"
5466 " p.prsstart::pg_catalog.regproc AS \"%s\",\n"
5467 " pg_catalog.obj_description(p.prsstart, 'pg_proc') as \"%s\"\n"
5468 " FROM pg_catalog.pg_ts_parser p\n"
5469 " WHERE p.oid = '%s'\n"
5472 " p.prstoken::pg_catalog.regproc,\n"
5473 " pg_catalog.obj_description(p.prstoken, 'pg_proc')\n"
5474 " FROM pg_catalog.pg_ts_parser p\n"
5475 " WHERE p.oid = '%s'\n"
5478 " p.prsend::pg_catalog.regproc,\n"
5479 " pg_catalog.obj_description(p.prsend, 'pg_proc')\n"
5480 " FROM pg_catalog.pg_ts_parser p\n"
5481 " WHERE p.oid = '%s'\n"
5484 " p.prsheadline::pg_catalog.regproc,\n"
5485 " pg_catalog.obj_description(p.prsheadline, 'pg_proc')\n"
5486 " FROM pg_catalog.pg_ts_parser p\n"
5487 " WHERE p.oid = '%s'\n"
5490 " p.prslextype::pg_catalog.regproc,\n"
5491 " pg_catalog.obj_description(p.prslextype, 'pg_proc')\n"
5492 " FROM pg_catalog.pg_ts_parser p\n"
5493 " WHERE p.oid = '%s';",
5533 "SELECT t.alias as \"%s\",\n"
5534 " t.description as \"%s\"\n"
5535 "FROM pg_catalog.ts_token_type( '%s'::pg_catalog.oid ) as t\n"
5584 " n.nspname as \"%s\",\n"
5585 " d.dictname as \"%s\",\n",
5592 " ( SELECT COALESCE(nt.nspname, '(null)')::pg_catalog.text || '.' || t.tmplname FROM\n"
5593 " pg_catalog.pg_ts_template t\n"
5594 " LEFT JOIN pg_catalog.pg_namespace nt ON nt.oid = t.tmplnamespace\n"
5595 " WHERE d.dicttemplate = t.oid ) AS \"%s\",\n"
5596 " d.dictinitoption as \"%s\",\n",
5602 " pg_catalog.obj_description(d.oid, 'pg_ts_dict') as \"%s\"\n",
5606 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = d.dictnamespace\n");
5609 "n.nspname",
"d.dictname", NULL,
5610 "pg_catalog.pg_ts_dict_is_visible(d.oid)",
5624 myopt.
title =
_(
"List of text search dictionaries");
5650 " n.nspname AS \"%s\",\n"
5651 " t.tmplname AS \"%s\",\n"
5652 " t.tmplinit::pg_catalog.regproc AS \"%s\",\n"
5653 " t.tmpllexize::pg_catalog.regproc AS \"%s\",\n"
5654 " pg_catalog.obj_description(t.oid, 'pg_ts_template') AS \"%s\"\n",
5663 " n.nspname AS \"%s\",\n"
5664 " t.tmplname AS \"%s\",\n"
5665 " pg_catalog.obj_description(t.oid, 'pg_ts_template') AS \"%s\"\n",
5671 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = t.tmplnamespace\n");
5674 "n.nspname",
"t.tmplname", NULL,
5675 "pg_catalog.pg_ts_template_is_visible(t.oid)",
5689 myopt.
title =
_(
"List of text search templates");
5717 " n.nspname as \"%s\",\n"
5718 " c.cfgname as \"%s\",\n"
5719 " pg_catalog.obj_description(c.oid, 'pg_ts_config') as \"%s\"\n"
5720 "FROM pg_catalog.pg_ts_config c\n"
5721 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.cfgnamespace\n",
5728 "n.nspname",
"c.cfgname", NULL,
5729 "pg_catalog.pg_ts_config_is_visible(c.oid)",
5743 myopt.
title =
_(
"List of text search configurations");
5762 "SELECT c.oid, c.cfgname,\n"
5765 " np.nspname as pnspname\n"
5766 "FROM pg_catalog.pg_ts_config c\n"
5767 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.cfgnamespace,\n"
5768 " pg_catalog.pg_ts_parser p\n"
5769 " LEFT JOIN pg_catalog.pg_namespace np ON np.oid = p.prsnamespace\n"
5770 "WHERE p.oid = c.cfgparser\n"
5774 "n.nspname",
"c.cfgname", NULL,
5775 "pg_catalog.pg_ts_config_is_visible(c.oid)",
5794 pg_log_error(
"Did not find any text search configuration named \"%s\".",
5797 pg_log_error(
"Did not find any text search configurations.");
5806 const char *cfgname;
5807 const char *nspname = NULL;
5808 const char *prsname;
5809 const char *pnspname = NULL;
5838 const char *pnspname,
const char *prsname)
5849 " ( SELECT t.alias FROM\n"
5850 " pg_catalog.ts_token_type(c.cfgparser) AS t\n"
5851 " WHERE t.tokid = m.maptokentype ) AS \"%s\",\n"
5852 " pg_catalog.btrim(\n"
5853 " ARRAY( SELECT mm.mapdict::pg_catalog.regdictionary\n"
5854 " FROM pg_catalog.pg_ts_config_map AS mm\n"
5855 " WHERE mm.mapcfg = m.mapcfg AND mm.maptokentype = m.maptokentype\n"
5856 " ORDER BY mapcfg, maptokentype, mapseqno\n"
5857 " ) :: pg_catalog.text,\n"
5858 " '{}') AS \"%s\"\n"
5859 "FROM pg_catalog.pg_ts_config AS c, pg_catalog.pg_ts_config_map AS m\n"
5860 "WHERE c.oid = '%s' AND m.mapcfg = c.oid\n"
5861 "GROUP BY m.mapcfg, m.maptokentype, c.cfgparser\n"
5916 "SELECT fdw.fdwname AS \"%s\",\n"
5917 " pg_catalog.pg_get_userbyid(fdw.fdwowner) AS \"%s\",\n"
5918 " fdw.fdwhandler::pg_catalog.regproc AS \"%s\",\n"
5919 " fdw.fdwvalidator::pg_catalog.regproc AS \"%s\"",
5930 ",\n CASE WHEN fdwoptions IS NULL THEN '' ELSE "
5931 " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
5932 " pg_catalog.quote_ident(option_name) || ' ' || "
5933 " pg_catalog.quote_literal(option_value) FROM "
5934 " pg_catalog.pg_options_to_table(fdwoptions)), ', ') || ')' "
5936 ",\n d.description AS \"%s\" ",
5945 "LEFT JOIN pg_catalog.pg_description d\n"
5946 " ON d.classoid = fdw.tableoid "
5947 "AND d.objoid = fdw.oid AND d.objsubid = 0\n");
5950 NULL,
"fdwname", NULL, NULL,
5964 myopt.
title =
_(
"List of foreign-data wrappers");
5987 "SELECT s.srvname AS \"%s\",\n"
5988 " pg_catalog.pg_get_userbyid(s.srvowner) AS \"%s\",\n"
5989 " f.fdwname AS \"%s\"",
6000 " s.srvtype AS \"%s\",\n"
6001 " s.srvversion AS \"%s\",\n"
6002 " CASE WHEN srvoptions IS NULL THEN '' ELSE "
6003 " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
6004 " pg_catalog.quote_ident(option_name) || ' ' || "
6005 " pg_catalog.quote_literal(option_value) FROM "
6006 " pg_catalog.pg_options_to_table(srvoptions)), ', ') || ')' "
6008 " d.description AS \"%s\"",
6016 "\nFROM pg_catalog.pg_foreign_server s\n"
6017 " JOIN pg_catalog.pg_foreign_data_wrapper f ON f.oid=s.srvfdw\n");
6021 "LEFT JOIN pg_catalog.pg_description d\n "
6022 "ON d.classoid = s.tableoid AND d.objoid = s.oid "
6023 "AND d.objsubid = 0\n");
6026 NULL,
"s.srvname", NULL, NULL,
6040 myopt.
title =
_(
"List of foreign servers");
6063 "SELECT um.srvname AS \"%s\",\n"
6064 " um.usename AS \"%s\"",
6070 ",\n CASE WHEN umoptions IS NULL THEN '' ELSE "
6071 " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
6072 " pg_catalog.quote_ident(option_name) || ' ' || "
6073 " pg_catalog.quote_literal(option_value) FROM "
6074 " pg_catalog.pg_options_to_table(umoptions)), ', ') || ')' "
6081 NULL,
"um.srvname",
"um.usename", NULL,
6095 myopt.
title =
_(
"List of user mappings");
6118 "SELECT n.nspname AS \"%s\",\n"
6119 " c.relname AS \"%s\",\n"
6120 " s.srvname AS \"%s\"",
6127 ",\n CASE WHEN ftoptions IS NULL THEN '' ELSE "
6128 " '(' || pg_catalog.array_to_string(ARRAY(SELECT "
6129 " pg_catalog.quote_ident(option_name) || ' ' || "
6130 " pg_catalog.quote_literal(option_value) FROM "
6131 " pg_catalog.pg_options_to_table(ftoptions)), ', ') || ')' "
6133 " d.description AS \"%s\"",
6138 "\nFROM pg_catalog.pg_foreign_table ft\n"
6139 " INNER JOIN pg_catalog.pg_class c"
6140 " ON c.oid = ft.ftrelid\n"
6141 " INNER JOIN pg_catalog.pg_namespace n"
6142 " ON n.oid = c.relnamespace\n"
6143 " INNER JOIN pg_catalog.pg_foreign_server s"
6144 " ON s.oid = ft.ftserver\n");
6147 " LEFT JOIN pg_catalog.pg_description d\n"
6148 " ON d.classoid = c.tableoid AND "
6149 "d.objoid = c.oid AND d.objsubid = 0\n");
6152 "n.nspname",
"c.relname", NULL,
6153 "pg_catalog.pg_table_is_visible(c.oid)",
6167 myopt.
title =
_(
"List of foreign tables");
6190 "SELECT e.extname AS \"%s\", "
6191 "e.extversion AS \"%s\", ae.default_version AS \"%s\","
6192 "n.nspname AS \"%s\", d.description AS \"%s\"\n"
6193 "FROM pg_catalog.pg_extension e "
6194 "LEFT JOIN pg_catalog.pg_namespace n ON n.oid = e.extnamespace "
6195 "LEFT JOIN pg_catalog.pg_description d ON d.objoid = e.oid "
6196 "LEFT JOIN pg_catalog.pg_available_extensions() ae(name, default_version, comment) ON ae.name = e.extname "
6197 "AND d.classoid = 'pg_catalog.pg_extension'::pg_catalog.regclass\n",
6206 NULL,
"e.extname", NULL,
6221 myopt.
title =
_(
"List of installed extensions");
6244 "SELECT e.extname, e.oid\n"
6245 "FROM pg_catalog.pg_extension e\n");
6249 NULL,
"e.extname", NULL,
6269 pg_log_error(
"Did not find any extension named \"%s\".",
6280 const char *extname;
6312 "SELECT pg_catalog.pg_describe_object(classid, objid, 0) AS \"%s\"\n"
6313 "FROM pg_catalog.pg_depend\n"
6314 "WHERE refclassid = 'pg_catalog.pg_extension'::pg_catalog.regclass AND refobjid = '%s' AND deptype = 'e'\n"
6348 bool force_escape,
const char *schemavar,
6349 const char *namevar,
const char *altnamevar,
6350 const char *visibilityrule,
bool *added_clause,
6359 schemavar, namevar, altnamevar,
6360 visibilityrule, &dbbuf, &dotcnt);
6361 if (added_clause != NULL)
6362 *added_clause = added;
6364 if (dotcnt >= maxparts)
6366 pg_log_error(
"improper qualified name (too many dotted names): %s",
6371 if (maxparts > 1 && dotcnt == maxparts - 1)
6375 pg_log_error(
"You are currently not connected to a database.");
6380 pg_log_error(
"cross-database references are not implemented: %s",
6405 static const bool translate_columns[] = {
false,
false,
false,
false,
false,
false,
false,
false,
false};
6411 pg_log_error(
"The server (version %s) does not support publications.",
6413 sverbuf,
sizeof(sverbuf)));
6420 "SELECT pubname AS \"%s\",\n"
6421 " pg_catalog.pg_get_userbyid(pubowner) AS \"%s\",\n"
6422 " puballtables AS \"%s\",\n"
6423 " pubinsert AS \"%s\",\n"
6424 " pubupdate AS \"%s\",\n"
6425 " pubdelete AS \"%s\"",
6434 ",\n pubtruncate AS \"%s\"",
6438 ",\n (CASE pubgencols\n"
6439 " WHEN '%c' THEN 'none'\n"
6440 " WHEN '%c' THEN 'stored'\n"
6442 PUBLISH_GENCOLS_NONE,
6443 PUBLISH_GENCOLS_STORED,
6447 ",\n pubviaroot AS \"%s\"",
6451 "\nFROM pg_catalog.pg_publication\n");
6454 NULL,
"pubname", NULL,
6469 myopt.
title =
_(
"List of publications");
6501 for (
i = 0;
i < count;
i++)
6536 bool has_pubtruncate;
6537 bool has_pubgencols;
6538 bool has_pubviaroot;
6547 pg_log_error(
"The server (version %s) does not support publications.",
6549 sverbuf,
sizeof(sverbuf)));
6560 "SELECT oid, pubname,\n"
6561 " pg_catalog.pg_get_userbyid(pubowner) AS owner,\n"
6562 " puballtables, pubinsert, pubupdate, pubdelete");
6563 if (has_pubtruncate)
6568 ", false AS pubtruncate");
6572 ", (CASE pubgencols\n"
6573 " WHEN '%c' THEN 'none'\n"
6574 " WHEN '%c' THEN 'stored'\n"
6575 " END) AS \"%s\"\n",
6576 PUBLISH_GENCOLS_NONE,
6577 PUBLISH_GENCOLS_STORED,
6581 ", 'none' AS pubgencols");
6588 ", false AS pubviaroot");
6591 "\nFROM pg_catalog.pg_publication\n");
6594 NULL,
"pubname", NULL,
6616 pg_log_error(
"Did not find any publication named \"%s\".",
6629 const char align =
'l';
6634 bool puballtables = strcmp(
PQgetvalue(res,
i, 3),
"t") == 0;
6637 if (has_pubtruncate)
6653 if (has_pubtruncate)
6665 if (has_pubtruncate)
6676 "SELECT n.nspname, c.relname");
6680 ", pg_get_expr(pr.prqual, c.oid)");
6682 ", (CASE WHEN pr.prattrs IS NOT NULL THEN\n"
6683 " pg_catalog.array_to_string("
6684 " ARRAY(SELECT attname\n"
6686 " pg_catalog.generate_series(0, pg_catalog.array_upper(pr.prattrs::pg_catalog.int2[], 1)) s,\n"
6687 " pg_catalog.pg_attribute\n"
6688 " WHERE attrelid = c.oid AND attnum = prattrs[s]), ', ')\n"
6695 "\nFROM pg_catalog.pg_class c,\n"
6696 " pg_catalog.pg_namespace n,\n"
6697 " pg_catalog.pg_publication_rel pr\n"
6698 "WHERE c.relnamespace = n.oid\n"
6699 " AND c.oid = pr.prrelid\n"
6700 " AND pr.prpubid = '%s'\n"
6701 "ORDER BY 1,2", pubid);
6709 "SELECT n.nspname\n"
6710 "FROM pg_catalog.pg_namespace n\n"
6711 " JOIN pg_catalog.pg_publication_namespace pn ON n.oid = pn.pnnspid\n"
6712 "WHERE pn.pnpubid = '%s'\n"
6713 "ORDER BY 1", pubid);
6751 static const bool translate_columns[] = {
false,
false,
false,
false,
6752 false,
false,
false,
false,
false,
false,
false,
false,
false,
false,
6759 pg_log_error(
"The server (version %s) does not support subscriptions.",
6761 sverbuf,
sizeof(sverbuf)));
6768 "SELECT subname AS \"%s\"\n"
6769 ", pg_catalog.pg_get_userbyid(subowner) AS \"%s\"\n"
6770 ", subenabled AS \"%s\"\n"
6771 ", subpublications AS \"%s\"\n",
6783 ", subbinary AS \"%s\"\n",
6788 ", (CASE substream\n"
6789 " WHEN " CppAsString2(LOGICALREP_STREAM_OFF)
" THEN 'off'\n"
6790 " WHEN " CppAsString2(LOGICALREP_STREAM_ON)
" THEN 'on'\n"
6791 " WHEN " CppAsString2(LOGICALREP_STREAM_PARALLEL)
" THEN 'parallel'\n"
6792 " END) AS \"%s\"\n",
6796 ", substream AS \"%s\"\n",
6803 ", subtwophasestate AS \"%s\"\n"
6804 ", subdisableonerr AS \"%s\"\n",
6810 ", suborigin AS \"%s\"\n"
6811 ", subpasswordrequired AS \"%s\"\n"
6812 ", subrunasowner AS \"%s\"\n",
6819 ", subfailover AS \"%s\"\n",
6823 ", subsynccommit AS \"%s\"\n"
6824 ", subconninfo AS \"%s\"\n",
6831 ", subskiplsn AS \"%s\"\n",
6837 "FROM pg_catalog.pg_subscription\n"
6838 "WHERE subdbid = (SELECT oid\n"
6839 " FROM pg_catalog.pg_database\n"
6840 " WHERE datname = pg_catalog.current_database())");
6843 NULL,
"subname", NULL,
6858 myopt.
title =
_(
"List of subscriptions");
6884 " WHEN pg_catalog.array_length(%s, 1) = 0 THEN '%s'"
6885 " ELSE pg_catalog.array_to_string(%s, E'\\n')"
6899 const char *type_pattern,
bool verbose)
6904 bool have_where =
false;
6905 static const bool translate_columns[] = {
false,
false,
false,
false,
false,
false,
false};
6911 " am.amname AS \"%s\",\n"
6912 " pg_catalog.format_type(c.opcintype, NULL) AS \"%s\",\n"
6914 " WHEN c.opckeytype <> 0 AND c.opckeytype <> c.opcintype\n"
6915 " THEN pg_catalog.format_type(c.opckeytype, NULL)\n"
6919 " WHEN pg_catalog.pg_opclass_is_visible(c.oid)\n"
6920 " THEN pg_catalog.format('%%I', c.opcname)\n"
6921 " ELSE pg_catalog.format('%%I.%%I', n.nspname, c.opcname)\n"
6923 " (CASE WHEN c.opcdefault\n"
6937 " WHEN pg_catalog.pg_opfamily_is_visible(of.oid)\n"
6938 " THEN pg_catalog.format('%%I', of.opfname)\n"
6939 " ELSE pg_catalog.format('%%I.%%I', ofn.nspname, of.opfname)\n"
6941 " pg_catalog.pg_get_userbyid(c.opcowner) AS \"%s\"\n",
6945 "\nFROM pg_catalog.pg_opclass c\n"
6946 " LEFT JOIN pg_catalog.pg_am am on am.oid = c.opcmethod\n"
6947 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = c.opcnamespace\n"
6948 " LEFT JOIN pg_catalog.pg_type t ON t.oid = c.opcintype\n"
6949 " LEFT JOIN pg_catalog.pg_namespace tn ON tn.oid = t.typnamespace\n");
6952 " LEFT JOIN pg_catalog.pg_opfamily of ON of.oid = c.opcfamily\n"
6953 " LEFT JOIN pg_catalog.pg_namespace ofn ON ofn.oid = of.opfnamespace\n");
6955 if (access_method_pattern)
6957 false,
false, NULL,
"am.amname", NULL, NULL,
6964 "tn.nspname",
"t.typname",
6965 "pg_catalog.format_type(t.oid, NULL)",
6966 "pg_catalog.pg_type_is_visible(t.oid)",
6977 myopt.
title =
_(
"List of operator classes");
7000 const char *type_pattern,
bool verbose)
7005 bool have_where =
false;
7006 static const bool translate_columns[] = {
false,
false,
false,
false};
7012 " am.amname AS \"%s\",\n"
7014 " WHEN pg_catalog.pg_opfamily_is_visible(f.oid)\n"
7015 " THEN pg_catalog.format('%%I', f.opfname)\n"
7016 " ELSE pg_catalog.format('%%I.%%I', n.nspname, f.opfname)\n"
7019 " pg_catalog.string_agg(pg_catalog.format_type(oc.opcintype, NULL), ', ')\n"
7020 " FROM pg_catalog.pg_opclass oc\n"
7021 " WHERE oc.opcfamily = f.oid) \"%s\"",
7027 ",\n pg_catalog.pg_get_userbyid(f.opfowner) AS \"%s\"\n",
7030 "\nFROM pg_catalog.pg_opfamily f\n"
7031 " LEFT JOIN pg_catalog.pg_am am on am.oid = f.opfmethod\n"
7032 " LEFT JOIN pg_catalog.pg_namespace n ON n.oid = f.opfnamespace\n");
7034 if (access_method_pattern)
7036 false,
false, NULL,
"am.amname", NULL, NULL,
7044 " FROM pg_catalog.pg_type t\n"
7045 " JOIN pg_catalog.pg_opclass oc ON oc.opcintype = t.oid\n"
7046 " LEFT JOIN pg_catalog.pg_namespace tn ON tn.oid = t.typnamespace\n"
7047 " WHERE oc.opcfamily = f.oid\n",
7048 have_where ?
"AND" :
"WHERE");
7051 "tn.nspname",
"t.typname",
7052 "pg_catalog.format_type(t.oid, NULL)",
7053 "pg_catalog.pg_type_is_visible(t.oid)",
7065 myopt.
title =
_(
"List of operator families");
7089 const char *family_pattern,
bool verbose)
7094 bool have_where =
false;
7096 static const bool translate_columns[] = {
false,
false,
false,
false,
false,
false,
true};
7102 " am.amname AS \"%s\",\n"
7104 " WHEN pg_catalog.pg_opfamily_is_visible(of.oid)\n"
7105 " THEN pg_catalog.format('%%I', of.opfname)\n"
7106 " ELSE pg_catalog.format('%%I.%%I', nsf.nspname, of.opfname)\n"
7108 " o.amopopr::pg_catalog.regoperator AS \"%s\"\n,"
7109 " o.amopstrategy AS \"%s\",\n"
7110 " CASE o.amoppurpose\n"
7124 ", ofs.opfname AS \"%s\",\n"
7126 " WHEN p.proleakproof THEN '%s'\n"
7134 "FROM pg_catalog.pg_amop o\n"
7135 " LEFT JOIN pg_catalog.pg_opfamily of ON of.oid = o.amopfamily\n"
7136 " LEFT JOIN pg_catalog.pg_am am ON am.oid = of.opfmethod AND am.oid = o.amopmethod\n"
7137 " LEFT JOIN pg_catalog.pg_namespace nsf ON of.opfnamespace = nsf.oid\n");
7140 " LEFT JOIN pg_catalog.pg_opfamily ofs ON ofs.oid = o.amopsortfamily\n"
7141 " LEFT JOIN pg_catalog.pg_operator op ON op.oid = o.amopopr\n"
7142 " LEFT JOIN pg_catalog.pg_proc p ON p.oid = op.oprcode\n");
7144 if (access_method_pattern)
7147 false,
false, NULL,
"am.amname",
7156 "nsf.nspname",
"of.opfname", NULL, NULL,
7162 " o.amoplefttype = o.amoprighttype DESC,\n"
7163 " pg_catalog.format_type(o.amoplefttype, NULL),\n"
7164 " pg_catalog.format_type(o.amoprighttype, NULL),\n"
7165 " o.amopstrategy;");
7172 myopt.
title =
_(
"List of operators of operator families");
7196 const char *family_pattern,
bool verbose)
7201 bool have_where =
false;
7202 static const bool translate_columns[] = {
false,
false,
false,
false,
false,
false};
7208 " am.amname AS \"%s\",\n"
7210 " WHEN pg_catalog.pg_opfamily_is_visible(of.oid)\n"
7211 " THEN pg_catalog.format('%%I', of.opfname)\n"
7212 " ELSE pg_catalog.format('%%I.%%I', ns.nspname, of.opfname)\n"
7214 " pg_catalog.format_type(ap.amproclefttype, NULL) AS \"%s\",\n"
7215 " pg_catalog.format_type(ap.amprocrighttype, NULL) AS \"%s\",\n"
7216 " ap.amprocnum AS \"%s\"\n",
7225 ", p.proname AS \"%s\"\n",
7229 ", ap.amproc::pg_catalog.regprocedure AS \"%s\"\n",
7233 "FROM pg_catalog.pg_amproc ap\n"
7234 " LEFT JOIN pg_catalog.pg_opfamily of ON of.oid = ap.amprocfamily\n"
7235 " LEFT JOIN pg_catalog.pg_am am ON am.oid = of.opfmethod\n"
7236 " LEFT JOIN pg_catalog.pg_namespace ns ON of.opfnamespace = ns.oid\n"
7237 " LEFT JOIN pg_catalog.pg_proc p ON ap.amproc = p.oid\n");
7239 if (access_method_pattern)
7242 false,
false, NULL,
"am.amname",
7250 "ns.nspname",
"of.opfname", NULL, NULL,
7256 " ap.amproclefttype = ap.amprocrighttype DESC,\n"
7264 myopt.
title =
_(
"List of support functions of operator families");
7293 "SELECT oid as \"%s\",\n"
7294 " pg_catalog.pg_get_userbyid(lomowner) as \"%s\",\n ",
7305 "pg_catalog.obj_description(oid, 'pg_largeobject') as \"%s\"\n"
7306 "FROM pg_catalog.pg_largeobject_metadata\n"
7315 myopt.
title =
_(
"Large objects");
PGresult * PSQLexec(const char *query)
#define ngettext(s, p, n)
bool listUserMappings(const char *pattern, bool verbose)
bool listTSConfigs(const char *pattern, bool verbose)
bool describeRoles(const char *pattern, bool verbose, bool showSystem)
bool listOpFamilyFunctions(const char *access_method_pattern, const char *family_pattern, bool verbose)
bool listPublications(const char *pattern)
bool listTSParsers(const char *pattern, bool verbose)
bool listExtensionContents(const char *pattern)
bool describeAggregates(const char *pattern, bool verbose, bool showSystem)
bool listForeignDataWrappers(const char *pattern, bool verbose)
bool listPartitionedTables(const char *reltypes, const char *pattern, bool verbose)
bool describeSubscriptions(const char *pattern, bool verbose)
bool describeRoleGrants(const char *pattern, bool showSystem)
bool listExtendedStats(const char *pattern)
bool describeTypes(const char *pattern, bool verbose, bool showSystem)
bool listOperatorFamilies(const char *access_method_pattern, const char *type_pattern, bool verbose)
bool listForeignServers(const char *pattern, bool verbose)
bool describeTableDetails(const char *pattern, bool verbose, bool showSystem)
bool listDomains(const char *pattern, bool verbose, bool showSystem)
bool listTSDictionaries(const char *pattern, bool verbose)
bool listDbRoleSettings(const char *pattern, const char *pattern2)
bool describeFunctions(const char *functypes, const char *func_pattern, char **arg_patterns, int num_arg_patterns, bool verbose, bool showSystem)
static void add_role_attribute(PQExpBuffer buf, const char *const str)
bool listCollations(const char *pattern, bool verbose, bool showSystem)
bool listSchemas(const char *pattern, bool verbose, bool showSystem)
bool listExtensions(const char *pattern)
static bool describeOneTSConfig(const char *oid, const char *nspname, const char *cfgname, const char *pnspname, const char *prsname)
static bool listOneExtensionContents(const char *extname, const char *oid)
static bool describeOneTableDetails(const char *schemaname, const char *relationname, const char *oid, bool verbose)
static bool listTSParsersVerbose(const char *pattern)
bool listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSystem)
bool listTSTemplates(const char *pattern, bool verbose)
bool describeTablespaces(const char *pattern, bool verbose)
bool listCasts(const char *pattern, bool verbose)
bool listOpFamilyOperators(const char *access_method_pattern, const char *family_pattern, bool verbose)
bool describeOperators(const char *oper_pattern, char **arg_patterns, int num_arg_patterns, bool verbose, bool showSystem)
bool listOperatorClasses(const char *access_method_pattern, const char *type_pattern, bool verbose)
static const char * map_typename_pattern(const char *pattern)
bool listForeignTables(const char *pattern, bool verbose)
bool describeConfigurationParameters(const char *pattern, bool verbose, bool showSystem)
bool listEventTriggers(const char *pattern, bool verbose)
bool listDefaultACLs(const char *pattern)
static void printACLColumn(PQExpBuffer buf, const char *colname)
static bool addFooterToPublicationDesc(PQExpBuffer buf, const char *footermsg, bool as_schema, printTableContent *const cont)
static bool validateSQLNamePattern(PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule, bool *added_clause, int maxparts)
bool listAllDbs(const char *pattern, bool verbose)
bool listConversions(const char *pattern, bool verbose, bool showSystem)
bool permissionsList(const char *pattern, bool showSystem)
bool describeAccessMethods(const char *pattern, bool verbose)
static bool listTSConfigsVerbose(const char *pattern)
bool listLargeObjects(bool verbose)
static bool describeOneTSParser(const char *oid, const char *nspname, const char *prsname)
static void add_tablespace_footer(printTableContent *const cont, char relkind, Oid tablespace, const bool newline)
bool listLanguages(const char *pattern, bool verbose, bool showSystem)
bool describePublications(const char *pattern)
bool objectDescription(const char *pattern, bool showSystem)
char * PQdb(const PGconn *conn)
char * PQgetvalue(const PGresult *res, int tup_num, int field_num)
void PQclear(PGresult *res)
int PQntuples(const PGresult *res)
int PQfnumber(const PGresult *res, const char *field_name)
int PQgetisnull(const PGresult *res, int tup_num, int field_num)
void * pg_malloc(size_t size)
char * pg_strdup(const char *in)
void * pg_malloc0(size_t size)
void printTableInit(printTableContent *const content, const printTableOpt *opt, const char *title, const int ncolumns, const int nrows)
void printTableCleanup(printTableContent *const content)
void printQuery(const PGresult *result, const printQueryOpt *opt, FILE *fout, bool is_pager, FILE *flog)
void printTableAddCell(printTableContent *const content, char *cell, const bool translate, const bool mustfree)
void printTableSetFooter(printTableContent *const content, const char *footer)
void printTable(const printTableContent *cont, FILE *fout, bool is_pager, FILE *flog)
void printTableAddFooter(printTableContent *const content, const char *footer)
void printTableAddHeader(printTableContent *const content, char *header, const bool translate, const char align)
volatile sig_atomic_t cancel_pressed
Assert(PointerIsAligned(start, uint64))
static IsoConnInfo * conns
#define pg_log_error_internal(...)
#define pg_log_error(...)
int pg_wcswidth(const char *pwcs, size_t len, int encoding)
int pg_strcasecmp(const char *s1, const char *s2)
void printfPQExpBuffer(PQExpBuffer str, const char *fmt,...)
void initPQExpBuffer(PQExpBuffer str)
void resetPQExpBuffer(PQExpBuffer str)
void appendPQExpBuffer(PQExpBuffer str, const char *fmt,...)
void appendPQExpBufferChar(PQExpBuffer str, char ch)
void appendPQExpBufferStr(PQExpBuffer str, const char *data)
void termPQExpBuffer(PQExpBuffer str)
char * psprintf(const char *fmt,...)
const char * fmtId(const char *rawid)
bool processSQLNamePattern(PGconn *conn, PQExpBuffer buf, const char *pattern, bool have_where, bool force_escape, const char *schemavar, const char *namevar, const char *altnamevar, const char *visibilityrule, PQExpBuffer dbnamebuf, int *dotcnt)
char * formatPGVersionNumber(int version_number, bool include_minor, char *buf, size_t buflen)
const bool * translate_columns
printTableFooter * footer
unsigned short int expanded
static StringInfoData tmpbuf