1
0
mirror of https://github.com/postgres/postgres.git synced 2026-10-23 13:29:09 +03:00

Add labels to help make psql's hidden queries more understandable.

We recommend looking at psql's "-E" output to help understand the
system catalogs, but in some cases (particularly table displays)
there's a bunch of rather impenetrable SQL there.  As a small
improvement, label each query issued by describe.c with a short
description of its purpose.  The code is arranged so that the
labels also appear as SQL comments in the server log, if the
server is logging these commands.

We could expand this policy to every use of PSQLexec(), but most of
the ones outside describe.c are issuing simple commands like "BEGIN"
or "COMMIT", which don't seem to need such glosses.  I did add
labels to the commands issued by \sf, \sv and friends.

Also, make the -E and log output for hidden queries say
"INTERNAL QUERY" not just "QUERY", to distinguish them from
user-written queries.

Author: Greg Sabino Mullane <htamfids@gmail.com>
Co-authored-by: David Christensen <david+pg@pgguru.net>
Reviewed-by: Tom Lane <tgl@sss.pgh.pa.us>
Discussion: https://postgr.es/m/CAKAnmmJz8Hh=8Ru8jgzySPWmLBhnv4=oc_0KRiz-UORJ0Dex+w@mail.gmail.com
This commit is contained in:
Tom Lane
2026-03-26 11:36:38 -04:00
parent cf66978d79
commit 41d69e6dcc
3 changed files with 226 additions and 100 deletions

View File

@@ -6158,14 +6158,14 @@ echo_hidden_command(const char *query)
{ {
if (pset.echo_hidden != PSQL_ECHO_HIDDEN_OFF) if (pset.echo_hidden != PSQL_ECHO_HIDDEN_OFF)
{ {
printf(_("/******** QUERY *********/\n" printf(_("/**** INTERNAL QUERY ****/\n"
"%s\n" "%s\n"
"/************************/\n\n"), query); "/************************/\n\n"), query);
fflush(stdout); fflush(stdout);
if (pset.logfile) if (pset.logfile)
{ {
fprintf(pset.logfile, fprintf(pset.logfile,
_("/******** QUERY *********/\n" _("/**** INTERNAL QUERY ****/\n"
"%s\n" "%s\n"
"/************************/\n\n"), query); "/************************/\n\n"), query);
fflush(pset.logfile); fflush(pset.logfile);
@@ -6202,6 +6202,7 @@ lookup_object_oid(EditableObjectType obj_type, const char *desc,
* query to retrieve the function's OID using a cast to regproc or * query to retrieve the function's OID using a cast to regproc or
* regprocedure (as appropriate). * regprocedure (as appropriate).
*/ */
printfPQExpBuffer(query, "/* %s */\n", _("Get function's OID"));
appendPQExpBufferStr(query, "SELECT "); appendPQExpBufferStr(query, "SELECT ");
appendStringLiteralConn(query, desc, pset.db); appendStringLiteralConn(query, desc, pset.db);
appendPQExpBuffer(query, "::pg_catalog.%s::pg_catalog.oid", appendPQExpBuffer(query, "::pg_catalog.%s::pg_catalog.oid",
@@ -6215,6 +6216,7 @@ lookup_object_oid(EditableObjectType obj_type, const char *desc,
* this code doesn't check if the relation is actually a view. * this code doesn't check if the relation is actually a view.
* We'll detect that in get_create_object_cmd(). * We'll detect that in get_create_object_cmd().
*/ */
printfPQExpBuffer(query, "/* %s */\n", _("Get view's OID"));
appendPQExpBufferStr(query, "SELECT "); appendPQExpBufferStr(query, "SELECT ");
appendStringLiteralConn(query, desc, pset.db); appendStringLiteralConn(query, desc, pset.db);
appendPQExpBufferStr(query, "::pg_catalog.regclass::pg_catalog.oid"); appendPQExpBufferStr(query, "::pg_catalog.regclass::pg_catalog.oid");
@@ -6256,7 +6258,8 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid,
switch (obj_type) switch (obj_type)
{ {
case EditableFunction: case EditableFunction:
printfPQExpBuffer(query, printfPQExpBuffer(query, "/* %s */\n", _("Get function's definition"));
appendPQExpBuffer(query,
"SELECT pg_catalog.pg_get_functiondef(%u)", "SELECT pg_catalog.pg_get_functiondef(%u)",
oid); oid);
break; break;
@@ -6275,9 +6278,10 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid,
* separately. Materialized views (introduced in 9.3) may have * separately. Materialized views (introduced in 9.3) may have
* arbitrary storage parameter reloptions. * arbitrary storage parameter reloptions.
*/ */
printfPQExpBuffer(query, "/* %s */\n", _("Get view's definition and details"));
if (pset.sversion >= 90400) if (pset.sversion >= 90400)
{ {
printfPQExpBuffer(query, appendPQExpBuffer(query,
"SELECT nspname, relname, relkind, " "SELECT nspname, relname, relkind, "
"pg_catalog.pg_get_viewdef(c.oid, true), " "pg_catalog.pg_get_viewdef(c.oid, true), "
"pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, " "pg_catalog.array_remove(pg_catalog.array_remove(c.reloptions,'check_option=local'),'check_option=cascaded') AS reloptions, "
@@ -6290,7 +6294,7 @@ get_create_object_cmd(EditableObjectType obj_type, Oid oid,
} }
else else
{ {
printfPQExpBuffer(query, appendPQExpBuffer(query,
"SELECT nspname, relname, relkind, " "SELECT nspname, relname, relkind, "
"pg_catalog.pg_get_viewdef(c.oid, true), " "pg_catalog.pg_get_viewdef(c.oid, true), "
"c.reloptions AS reloptions, " "c.reloptions AS reloptions, "

View File

@@ -664,14 +664,14 @@ PSQLexec(const char *query)
if (pset.echo_hidden != PSQL_ECHO_HIDDEN_OFF) if (pset.echo_hidden != PSQL_ECHO_HIDDEN_OFF)
{ {
printf(_("/******** QUERY *********/\n" printf(_("/**** INTERNAL QUERY ****/\n"
"%s\n" "%s\n"
"/************************/\n\n"), query); "/************************/\n\n"), query);
fflush(stdout); fflush(stdout);
if (pset.logfile) if (pset.logfile)
{ {
fprintf(pset.logfile, fprintf(pset.logfile,
_("/******** QUERY *********/\n" _("/**** INTERNAL QUERY ****/\n"
"%s\n" "%s\n"
"/************************/\n\n"), query); "/************************/\n\n"), query);
fflush(pset.logfile); fflush(pset.logfile);

View File

@@ -84,7 +84,8 @@ describeAggregates(const char *pattern, bool verbose, bool showSystem)
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching aggregates"));
appendPQExpBuffer(&buf,
"SELECT n.nspname as \"%s\",\n" "SELECT n.nspname as \"%s\",\n"
" p.proname AS \"%s\",\n" " p.proname AS \"%s\",\n"
" pg_catalog.format_type(p.prorettype, NULL) AS \"%s\",\n" " pg_catalog.format_type(p.prorettype, NULL) AS \"%s\",\n"
@@ -165,7 +166,8 @@ describeAccessMethods(const char *pattern, bool verbose)
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching access methods"));
appendPQExpBuffer(&buf,
"SELECT amname AS \"%s\",\n" "SELECT amname AS \"%s\",\n"
" CASE amtype" " CASE amtype"
" WHEN " CppAsString2(AMTYPE_INDEX) " THEN '%s'" " WHEN " CppAsString2(AMTYPE_INDEX) " THEN '%s'"
@@ -228,7 +230,8 @@ describeTablespaces(const char *pattern, bool verbose)
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching tablespaces"));
appendPQExpBuffer(&buf,
"SELECT spcname AS \"%s\",\n" "SELECT spcname AS \"%s\",\n"
" pg_catalog.pg_get_userbyid(spcowner) AS \"%s\",\n" " pg_catalog.pg_get_userbyid(spcowner) AS \"%s\",\n"
" pg_catalog.pg_tablespace_location(oid) AS \"%s\"", " pg_catalog.pg_tablespace_location(oid) AS \"%s\"",
@@ -338,7 +341,8 @@ describeFunctions(const char *functypes, const char *func_pattern,
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching functions"));
appendPQExpBuffer(&buf,
"SELECT n.nspname as \"%s\",\n" "SELECT n.nspname as \"%s\",\n"
" p.proname as \"%s\",\n", " p.proname as \"%s\",\n",
gettext_noop("Schema"), gettext_noop("Schema"),
@@ -645,7 +649,8 @@ describeTypes(const char *pattern, bool verbose, bool showSystem)
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching types"));
appendPQExpBuffer(&buf,
"SELECT n.nspname as \"%s\",\n" "SELECT n.nspname as \"%s\",\n"
" pg_catalog.format_type(t.oid, NULL) AS \"%s\",\n", " pg_catalog.format_type(t.oid, NULL) AS \"%s\",\n",
gettext_noop("Schema"), gettext_noop("Schema"),
@@ -819,7 +824,8 @@ describeOperators(const char *oper_pattern,
* to pre-v14 servers. * to pre-v14 servers.
*/ */
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching operators"));
appendPQExpBuffer(&buf,
"SELECT n.nspname as \"%s\",\n" "SELECT n.nspname as \"%s\",\n"
" o.oprname AS \"%s\",\n" " o.oprname AS \"%s\",\n"
" CASE WHEN o.oprkind='l' THEN NULL ELSE pg_catalog.format_type(o.oprleft, NULL) END AS \"%s\",\n" " CASE WHEN o.oprkind='l' THEN NULL ELSE pg_catalog.format_type(o.oprleft, NULL) END AS \"%s\",\n"
@@ -952,7 +958,8 @@ listAllDbs(const char *pattern, bool verbose)
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching databases"));
appendPQExpBuffer(&buf,
"SELECT\n" "SELECT\n"
" d.datname as \"%s\",\n" " d.datname as \"%s\",\n"
" pg_catalog.pg_get_userbyid(d.datdba) as \"%s\",\n" " pg_catalog.pg_get_userbyid(d.datdba) as \"%s\",\n"
@@ -1060,7 +1067,9 @@ permissionsList(const char *pattern, bool showSystem)
/* /*
* we ignore indexes and toast tables since they have no meaningful rights * we ignore indexes and toast tables since they have no meaningful rights
*/ */
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n",
_("Get access privileges of matching relations"));
appendPQExpBuffer(&buf,
"SELECT n.nspname as \"%s\",\n" "SELECT n.nspname as \"%s\",\n"
" c.relname as \"%s\",\n" " c.relname as \"%s\",\n"
" CASE c.relkind" " CASE c.relkind"
@@ -1224,7 +1233,8 @@ listDefaultACLs(const char *pattern)
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching default ACLs"));
appendPQExpBuffer(&buf,
"SELECT pg_catalog.pg_get_userbyid(d.defaclrole) AS \"%s\",\n" "SELECT pg_catalog.pg_get_userbyid(d.defaclrole) AS \"%s\",\n"
" n.nspname AS \"%s\",\n" " n.nspname AS \"%s\",\n"
" CASE d.defaclobjtype " " CASE d.defaclobjtype "
@@ -1305,6 +1315,7 @@ objectDescription(const char *pattern, bool showSystem)
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching object comments"));
appendPQExpBuffer(&buf, appendPQExpBuffer(&buf,
"SELECT DISTINCT tt.nspname AS \"%s\", tt.name AS \"%s\", tt.object AS \"%s\", d.description AS \"%s\"\n" "SELECT DISTINCT tt.nspname AS \"%s\", tt.name AS \"%s\", tt.object AS \"%s\", d.description AS \"%s\"\n"
"FROM (\n", "FROM (\n",
@@ -1497,7 +1508,9 @@ describeTableDetails(const char *pattern, bool verbose, bool showSystem)
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n",
_("Get matching relations to describe"));
appendPQExpBuffer(&buf,
"SELECT c.oid,\n" "SELECT c.oid,\n"
" n.nspname,\n" " n.nspname,\n"
" c.relname\n" " c.relname\n"
@@ -1633,9 +1646,11 @@ describeOneTableDetails(const char *schemaname,
initPQExpBuffer(&tmpbuf); initPQExpBuffer(&tmpbuf);
/* Get general table info */ /* Get general table info */
printfPQExpBuffer(&buf, "/* %s */\n",
_("Get general information about one relation"));
if (pset.sversion >= 120000) if (pset.sversion >= 120000)
{ {
printfPQExpBuffer(&buf, appendPQExpBuffer(&buf,
"SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, " "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
"c.relhastriggers, c.relrowsecurity, c.relforcerowsecurity, " "c.relhastriggers, c.relrowsecurity, c.relforcerowsecurity, "
"false AS relhasoids, c.relispartition, %s, c.reltablespace, " "false AS relhasoids, c.relispartition, %s, c.reltablespace, "
@@ -1653,7 +1668,7 @@ describeOneTableDetails(const char *schemaname,
} }
else if (pset.sversion >= 100000) else if (pset.sversion >= 100000)
{ {
printfPQExpBuffer(&buf, appendPQExpBuffer(&buf,
"SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, " "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
"c.relhastriggers, c.relrowsecurity, c.relforcerowsecurity, " "c.relhastriggers, c.relrowsecurity, c.relforcerowsecurity, "
"c.relhasoids, c.relispartition, %s, c.reltablespace, " "c.relhasoids, c.relispartition, %s, c.reltablespace, "
@@ -1670,7 +1685,7 @@ describeOneTableDetails(const char *schemaname,
} }
else if (pset.sversion >= 90500) else if (pset.sversion >= 90500)
{ {
printfPQExpBuffer(&buf, appendPQExpBuffer(&buf,
"SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, " "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
"c.relhastriggers, c.relrowsecurity, c.relforcerowsecurity, " "c.relhastriggers, c.relrowsecurity, c.relforcerowsecurity, "
"c.relhasoids, false as relispartition, %s, c.reltablespace, " "c.relhasoids, false as relispartition, %s, c.reltablespace, "
@@ -1687,7 +1702,7 @@ describeOneTableDetails(const char *schemaname,
} }
else if (pset.sversion >= 90400) else if (pset.sversion >= 90400)
{ {
printfPQExpBuffer(&buf, appendPQExpBuffer(&buf,
"SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, " "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
"c.relhastriggers, false, false, c.relhasoids, " "c.relhastriggers, false, false, c.relhasoids, "
"false as relispartition, %s, c.reltablespace, " "false as relispartition, %s, c.reltablespace, "
@@ -1704,7 +1719,7 @@ describeOneTableDetails(const char *schemaname,
} }
else else
{ {
printfPQExpBuffer(&buf, appendPQExpBuffer(&buf,
"SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, " "SELECT c.relchecks, c.relkind, c.relhasindex, c.relhasrules, "
"c.relhastriggers, false, false, c.relhasoids, " "c.relhastriggers, false, false, c.relhasoids, "
"false as relispartition, %s, c.reltablespace, " "false as relispartition, %s, c.reltablespace, "
@@ -1765,9 +1780,10 @@ describeOneTableDetails(const char *schemaname,
printQueryOpt myopt = pset.popt; printQueryOpt myopt = pset.popt;
char *footers[3] = {NULL, NULL, NULL}; char *footers[3] = {NULL, NULL, NULL};
printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence information"));
if (pset.sversion >= 100000) if (pset.sversion >= 100000)
{ {
printfPQExpBuffer(&buf, appendPQExpBuffer(&buf,
"SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n" "SELECT pg_catalog.format_type(seqtypid, NULL) AS \"%s\",\n"
" seqstart AS \"%s\",\n" " seqstart AS \"%s\",\n"
" seqmin AS \"%s\",\n" " seqmin AS \"%s\",\n"
@@ -1791,7 +1807,7 @@ describeOneTableDetails(const char *schemaname,
} }
else else
{ {
printfPQExpBuffer(&buf, appendPQExpBuffer(&buf,
"SELECT 'bigint' AS \"%s\",\n" "SELECT 'bigint' AS \"%s\",\n"
" start_value AS \"%s\",\n" " start_value AS \"%s\",\n"
" min_value AS \"%s\",\n" " min_value AS \"%s\",\n"
@@ -1818,7 +1834,9 @@ describeOneTableDetails(const char *schemaname,
goto error_return; goto error_return;
/* Get the column that owns this sequence */ /* Get the column that owns this sequence */
printfPQExpBuffer(&buf, "SELECT pg_catalog.quote_ident(nspname) || '.' ||" printfPQExpBuffer(&buf, "/* %s */\n",
_("Get the column that owns this sequence"));
appendPQExpBuffer(&buf, "SELECT pg_catalog.quote_ident(nspname) || '.' ||"
"\n pg_catalog.quote_ident(relname) || '.' ||" "\n pg_catalog.quote_ident(relname) || '.' ||"
"\n pg_catalog.quote_ident(attname)," "\n pg_catalog.quote_ident(attname),"
"\n d.deptype" "\n d.deptype"
@@ -1862,7 +1880,9 @@ describeOneTableDetails(const char *schemaname,
/* Print any publications */ /* Print any publications */
if (pset.sversion >= 190000) if (pset.sversion >= 190000)
{ {
printfPQExpBuffer(&buf, "SELECT pubname FROM pg_catalog.pg_publication p" printfPQExpBuffer(&buf, "/* %s */\n",
_("Get publications containing this sequence"));
appendPQExpBuffer(&buf, "SELECT pubname FROM pg_catalog.pg_publication p"
"\nWHERE p.puballsequences" "\nWHERE p.puballsequences"
"\n AND pg_catalog.pg_relation_is_publishable('%s')" "\n AND pg_catalog.pg_relation_is_publishable('%s')"
"\nORDER BY 1", "\nORDER BY 1",
@@ -1921,7 +1941,8 @@ describeOneTableDetails(const char *schemaname,
printQueryOpt myopt = pset.popt; printQueryOpt myopt = pset.popt;
char *footers[3] = {NULL, NULL, NULL}; char *footers[3] = {NULL, NULL, NULL};
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n", _("Get property graph information"));
appendPQExpBuffer(&buf,
"SELECT e.pgealias AS \"%s\"," "SELECT e.pgealias AS \"%s\","
"\n pg_catalog.quote_ident(n.nspname) || '.' ||" "\n pg_catalog.quote_ident(n.nspname) || '.' ||"
"\n pg_catalog.quote_ident(c.relname) AS \"%s\"," "\n pg_catalog.quote_ident(c.relname) AS \"%s\","
@@ -1955,7 +1976,8 @@ describeOneTableDetails(const char *schemaname,
{ {
PGresult *result; PGresult *result;
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n", _("Get property graph definition"));
appendPQExpBuffer(&buf,
"SELECT pg_catalog.pg_get_propgraphdef('%s'::pg_catalog.oid);", "SELECT pg_catalog.pg_get_propgraphdef('%s'::pg_catalog.oid);",
oid); oid);
result = PSQLexec(buf.data); result = PSQLexec(buf.data);
@@ -2003,7 +2025,9 @@ describeOneTableDetails(const char *schemaname,
* duplicative test logic below. * duplicative test logic below.
*/ */
cols = 0; cols = 0;
printfPQExpBuffer(&buf, "SELECT a.attname"); printfPQExpBuffer(&buf, "/* %s */\n",
_("Get per-column information for one relation"));
appendPQExpBuffer(&buf, "SELECT a.attname");
attname_col = cols++; attname_col = cols++;
appendPQExpBufferStr(&buf, ",\n pg_catalog.format_type(a.atttypid, a.atttypmod)"); appendPQExpBufferStr(&buf, ",\n pg_catalog.format_type(a.atttypid, a.atttypmod)");
atttype_col = cols++; atttype_col = cols++;
@@ -2305,7 +2329,9 @@ describeOneTableDetails(const char *schemaname,
/* Footer information for a partition child table */ /* Footer information for a partition child table */
PGresult *result; PGresult *result;
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n",
_("Get partitioning information for this partition"));
appendPQExpBuffer(&buf,
"SELECT inhparent::pg_catalog.regclass,\n" "SELECT inhparent::pg_catalog.regclass,\n"
" pg_catalog.pg_get_expr(c.relpartbound, c.oid),\n "); " pg_catalog.pg_get_expr(c.relpartbound, c.oid),\n ");
@@ -2360,7 +2386,9 @@ describeOneTableDetails(const char *schemaname,
/* Footer information for a partitioned table (partitioning parent) */ /* Footer information for a partitioned table (partitioning parent) */
PGresult *result; PGresult *result;
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n",
_("Get partitioning information for this table"));
appendPQExpBuffer(&buf,
"SELECT pg_catalog.pg_get_partkeydef('%s'::pg_catalog.oid);", "SELECT pg_catalog.pg_get_partkeydef('%s'::pg_catalog.oid);",
oid); oid);
result = PSQLexec(buf.data); result = PSQLexec(buf.data);
@@ -2382,7 +2410,9 @@ describeOneTableDetails(const char *schemaname,
/* For a TOAST table, print name of owning table */ /* For a TOAST table, print name of owning table */
PGresult *result; PGresult *result;
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n",
_("Get the table that owns this TOAST table"));
appendPQExpBuffer(&buf,
"SELECT n.nspname, c.relname\n" "SELECT n.nspname, c.relname\n"
"FROM pg_catalog.pg_class c" "FROM pg_catalog.pg_class c"
" JOIN pg_catalog.pg_namespace n" " JOIN pg_catalog.pg_namespace n"
@@ -2410,7 +2440,8 @@ describeOneTableDetails(const char *schemaname,
/* Footer information about an index */ /* Footer information about an index */
PGresult *result; PGresult *result;
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n", _("Get index details"));
appendPQExpBuffer(&buf,
"SELECT i.indisunique, i.indisprimary, i.indisclustered, " "SELECT i.indisunique, i.indisprimary, i.indisclustered, "
"i.indisvalid,\n" "i.indisvalid,\n"
" (NOT i.indimmediate) AND " " (NOT i.indimmediate) AND "
@@ -2531,7 +2562,8 @@ describeOneTableDetails(const char *schemaname,
/* print indexes */ /* print indexes */
if (tableinfo.hasindex) if (tableinfo.hasindex)
{ {
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n", _("Get indexes for this table"));
appendPQExpBuffer(&buf,
"SELECT c2.relname, i.indisprimary, i.indisunique, " "SELECT c2.relname, i.indisprimary, i.indisunique, "
"i.indisclustered, i.indisvalid, " "i.indisclustered, i.indisvalid, "
"pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n " "pg_catalog.pg_get_indexdef(i.indexrelid, 0, true),\n "
@@ -2635,7 +2667,9 @@ describeOneTableDetails(const char *schemaname,
/* print table (and column) check constraints */ /* print table (and column) check constraints */
if (tableinfo.checks) if (tableinfo.checks)
{ {
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n",
_("Get check constraints for this table"));
appendPQExpBuffer(&buf,
"SELECT r.conname, " "SELECT r.conname, "
"pg_catalog.pg_get_constraintdef(r.oid, true)\n" "pg_catalog.pg_get_constraintdef(r.oid, true)\n"
"FROM pg_catalog.pg_constraint r\n" "FROM pg_catalog.pg_constraint r\n"
@@ -2666,6 +2700,8 @@ describeOneTableDetails(const char *schemaname,
} }
/* Print foreign-key constraints */ /* Print foreign-key constraints */
printfPQExpBuffer(&buf, "/* %s */\n",
_("Get foreign key constraints for this table"));
if (pset.sversion >= 120000 && if (pset.sversion >= 120000 &&
(tableinfo.ispartition || tableinfo.relkind == RELKIND_PARTITIONED_TABLE)) (tableinfo.ispartition || tableinfo.relkind == RELKIND_PARTITIONED_TABLE))
{ {
@@ -2673,7 +2709,7 @@ describeOneTableDetails(const char *schemaname,
* Put the constraints defined in this table first, followed by * Put the constraints defined in this table first, followed by
* the constraints defined in ancestor partitioned tables. * the constraints defined in ancestor partitioned tables.
*/ */
printfPQExpBuffer(&buf, appendPQExpBuffer(&buf,
"SELECT conrelid = '%s'::pg_catalog.regclass AS sametable,\n" "SELECT conrelid = '%s'::pg_catalog.regclass AS sametable,\n"
" conname,\n" " conname,\n"
" pg_catalog.pg_get_constraintdef(oid, true) AS condef,\n" " pg_catalog.pg_get_constraintdef(oid, true) AS condef,\n"
@@ -2686,7 +2722,7 @@ describeOneTableDetails(const char *schemaname,
} }
else else
{ {
printfPQExpBuffer(&buf, appendPQExpBuffer(&buf,
"SELECT true as sametable, conname,\n" "SELECT true as sametable, conname,\n"
" pg_catalog.pg_get_constraintdef(r.oid, true) as condef,\n" " pg_catalog.pg_get_constraintdef(r.oid, true) as condef,\n"
" conrelid::pg_catalog.regclass AS ontable\n" " conrelid::pg_catalog.regclass AS ontable\n"
@@ -2736,9 +2772,11 @@ describeOneTableDetails(const char *schemaname,
PQclear(result); PQclear(result);
/* print incoming foreign-key references */ /* print incoming foreign-key references */
printfPQExpBuffer(&buf, "/* %s */\n",
_("Get foreign keys referencing this table"));
if (pset.sversion >= 120000) if (pset.sversion >= 120000)
{ {
printfPQExpBuffer(&buf, appendPQExpBuffer(&buf,
"SELECT conname, conrelid::pg_catalog.regclass AS ontable,\n" "SELECT conname, conrelid::pg_catalog.regclass AS ontable,\n"
" pg_catalog.pg_get_constraintdef(oid, true) AS condef\n" " pg_catalog.pg_get_constraintdef(oid, true) AS condef\n"
" FROM pg_catalog.pg_constraint c\n" " FROM pg_catalog.pg_constraint c\n"
@@ -2750,7 +2788,7 @@ describeOneTableDetails(const char *schemaname,
} }
else else
{ {
printfPQExpBuffer(&buf, appendPQExpBuffer(&buf,
"SELECT conname, conrelid::pg_catalog.regclass AS ontable,\n" "SELECT conname, conrelid::pg_catalog.regclass AS ontable,\n"
" pg_catalog.pg_get_constraintdef(oid, true) AS condef\n" " pg_catalog.pg_get_constraintdef(oid, true) AS condef\n"
" FROM pg_catalog.pg_constraint\n" " FROM pg_catalog.pg_constraint\n"
@@ -2787,7 +2825,9 @@ describeOneTableDetails(const char *schemaname,
/* print any row-level policies */ /* print any row-level policies */
if (pset.sversion >= 90500) if (pset.sversion >= 90500)
{ {
printfPQExpBuffer(&buf, "SELECT pol.polname,"); printfPQExpBuffer(&buf, "/* %s */\n",
_("Get row-level policies for this table"));
appendPQExpBuffer(&buf, "SELECT pol.polname,");
if (pset.sversion >= 100000) if (pset.sversion >= 100000)
appendPQExpBufferStr(&buf, appendPQExpBufferStr(&buf,
" pol.polpermissive,\n"); " pol.polpermissive,\n");
@@ -2869,7 +2909,9 @@ describeOneTableDetails(const char *schemaname,
/* print any extended statistics */ /* print any extended statistics */
if (pset.sversion >= 140000) if (pset.sversion >= 140000)
{ {
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n",
_("Get extended statistics for this table"));
appendPQExpBuffer(&buf,
"SELECT oid, " "SELECT oid, "
"stxrelid::pg_catalog.regclass, " "stxrelid::pg_catalog.regclass, "
"stxnamespace::pg_catalog.regnamespace::pg_catalog.text AS nsp, " "stxnamespace::pg_catalog.regnamespace::pg_catalog.text AS nsp, "
@@ -2967,7 +3009,9 @@ describeOneTableDetails(const char *schemaname,
} }
else if (pset.sversion >= 100000) else if (pset.sversion >= 100000)
{ {
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n",
_("Get extended statistics for this table"));
appendPQExpBuffer(&buf,
"SELECT oid, " "SELECT oid, "
"stxrelid::pg_catalog.regclass, " "stxrelid::pg_catalog.regclass, "
"stxnamespace::pg_catalog.regnamespace AS nsp, " "stxnamespace::pg_catalog.regnamespace AS nsp, "
@@ -3046,7 +3090,9 @@ describeOneTableDetails(const char *schemaname,
/* print rules */ /* print rules */
if (tableinfo.hasrules && tableinfo.relkind != RELKIND_MATVIEW) if (tableinfo.hasrules && tableinfo.relkind != RELKIND_MATVIEW)
{ {
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n",
_("Get rules for this relation"));
appendPQExpBuffer(&buf,
"SELECT r.rulename, trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true)), " "SELECT r.rulename, trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true)), "
"ev_enabled\n" "ev_enabled\n"
"FROM pg_catalog.pg_rewrite r\n" "FROM pg_catalog.pg_rewrite r\n"
@@ -3129,9 +3175,11 @@ describeOneTableDetails(const char *schemaname,
/* print any publications */ /* print any publications */
if (pset.sversion >= 100000) if (pset.sversion >= 100000)
{ {
printfPQExpBuffer(&buf, "/* %s */\n",
_("Get publications that publish this table"));
if (pset.sversion >= 150000) if (pset.sversion >= 150000)
{ {
printfPQExpBuffer(&buf, appendPQExpBuffer(&buf,
"SELECT pubname\n" "SELECT pubname\n"
" , NULL\n" " , NULL\n"
" , NULL\n" " , NULL\n"
@@ -3191,7 +3239,7 @@ describeOneTableDetails(const char *schemaname,
} }
else else
{ {
printfPQExpBuffer(&buf, appendPQExpBuffer(&buf,
"SELECT pubname\n" "SELECT pubname\n"
" , NULL\n" " , NULL\n"
" , NULL\n" " , NULL\n"
@@ -3241,7 +3289,9 @@ describeOneTableDetails(const char *schemaname,
/* Print publications where the table is in the EXCEPT clause */ /* Print publications where the table is in the EXCEPT clause */
if (pset.sversion >= 190000) if (pset.sversion >= 190000)
{ {
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n",
_("Get publications that exclude this table"));
appendPQExpBuffer(&buf,
"SELECT pubname\n" "SELECT pubname\n"
"FROM pg_catalog.pg_publication p\n" "FROM pg_catalog.pg_publication p\n"
"JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n" "JOIN pg_catalog.pg_publication_rel pr ON p.oid = pr.prpubid\n"
@@ -3273,7 +3323,9 @@ describeOneTableDetails(const char *schemaname,
*/ */
if (verbose) if (verbose)
{ {
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n",
_("Get not-null constraints for this table"));
appendPQExpBuffer(&buf,
"SELECT c.conname, a.attname, c.connoinherit,\n" "SELECT c.conname, a.attname, c.connoinherit,\n"
" c.conislocal, c.coninhcount <> 0,\n" " c.conislocal, c.coninhcount <> 0,\n"
" c.convalidated\n" " c.convalidated\n"
@@ -3322,7 +3374,8 @@ describeOneTableDetails(const char *schemaname,
{ {
PGresult *result; PGresult *result;
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n", _("Get view's definition"));
appendPQExpBuffer(&buf,
"SELECT pg_catalog.pg_get_viewdef('%s'::pg_catalog.oid, true);", "SELECT pg_catalog.pg_get_viewdef('%s'::pg_catalog.oid, true);",
oid); oid);
result = PSQLexec(buf.data); result = PSQLexec(buf.data);
@@ -3346,7 +3399,8 @@ describeOneTableDetails(const char *schemaname,
/* print rules */ /* print rules */
if (tableinfo.hasrules) if (tableinfo.hasrules)
{ {
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n", _("Get rules for this view"));
appendPQExpBuffer(&buf,
"SELECT r.rulename, trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true))\n" "SELECT r.rulename, trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true))\n"
"FROM pg_catalog.pg_rewrite r\n" "FROM pg_catalog.pg_rewrite r\n"
"WHERE r.ev_class = '%s' AND r.rulename != '_RETURN' ORDER BY 1;", "WHERE r.ev_class = '%s' AND r.rulename != '_RETURN' ORDER BY 1;",
@@ -3383,7 +3437,9 @@ describeOneTableDetails(const char *schemaname,
PGresult *result; PGresult *result;
int tuples; int tuples;
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n",
_("Get triggers for this relation"));
appendPQExpBuffer(&buf,
"SELECT t.tgname, " "SELECT t.tgname, "
"pg_catalog.pg_get_triggerdef(t.oid, true), " "pg_catalog.pg_get_triggerdef(t.oid, true), "
"t.tgenabled, t.tgisinternal,\n"); "t.tgenabled, t.tgisinternal,\n");
@@ -3566,7 +3622,9 @@ describeOneTableDetails(const char *schemaname,
char *ftoptions; char *ftoptions;
/* Footer information about foreign table */ /* Footer information about foreign table */
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n",
_("Get foreign server for this table"));
appendPQExpBuffer(&buf,
"SELECT s.srvname,\n" "SELECT s.srvname,\n"
" pg_catalog.array_to_string(ARRAY(\n" " pg_catalog.array_to_string(ARRAY(\n"
" SELECT pg_catalog.quote_ident(option_name)" " SELECT pg_catalog.quote_ident(option_name)"
@@ -3601,7 +3659,9 @@ describeOneTableDetails(const char *schemaname,
} }
/* print tables inherited from (exclude partitioned parents) */ /* print tables inherited from (exclude partitioned parents) */
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n",
_("Get inheritance parent tables"));
appendPQExpBuffer(&buf,
"SELECT c.oid::pg_catalog.regclass\n" "SELECT c.oid::pg_catalog.regclass\n"
"FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n" "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n"
"WHERE c.oid = i.inhparent AND i.inhrelid = '%s'\n" "WHERE c.oid = i.inhparent AND i.inhrelid = '%s'\n"
@@ -3638,8 +3698,9 @@ describeOneTableDetails(const char *schemaname,
} }
/* print child tables (with additional info if partitions) */ /* print child tables (with additional info if partitions) */
printfPQExpBuffer(&buf, "/* %s */\n", _("Get child tables"));
if (pset.sversion >= 140000) if (pset.sversion >= 140000)
printfPQExpBuffer(&buf, appendPQExpBuffer(&buf,
"SELECT c.oid::pg_catalog.regclass, c.relkind," "SELECT c.oid::pg_catalog.regclass, c.relkind,"
" inhdetachpending," " inhdetachpending,"
" pg_catalog.pg_get_expr(c.relpartbound, c.oid)\n" " pg_catalog.pg_get_expr(c.relpartbound, c.oid)\n"
@@ -3649,7 +3710,7 @@ describeOneTableDetails(const char *schemaname,
" c.oid::pg_catalog.regclass::pg_catalog.text;", " c.oid::pg_catalog.regclass::pg_catalog.text;",
oid); oid);
else if (pset.sversion >= 100000) else if (pset.sversion >= 100000)
printfPQExpBuffer(&buf, appendPQExpBuffer(&buf,
"SELECT c.oid::pg_catalog.regclass, c.relkind," "SELECT c.oid::pg_catalog.regclass, c.relkind,"
" false AS inhdetachpending," " false AS inhdetachpending,"
" pg_catalog.pg_get_expr(c.relpartbound, c.oid)\n" " pg_catalog.pg_get_expr(c.relpartbound, c.oid)\n"
@@ -3659,7 +3720,7 @@ describeOneTableDetails(const char *schemaname,
" c.oid::pg_catalog.regclass::pg_catalog.text;", " c.oid::pg_catalog.regclass::pg_catalog.text;",
oid); oid);
else else
printfPQExpBuffer(&buf, appendPQExpBuffer(&buf,
"SELECT c.oid::pg_catalog.regclass, c.relkind," "SELECT c.oid::pg_catalog.regclass, c.relkind,"
" false AS inhdetachpending, NULL\n" " false AS inhdetachpending, NULL\n"
"FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n" "FROM pg_catalog.pg_class c, pg_catalog.pg_inherits i\n"
@@ -3833,7 +3894,9 @@ add_tablespace_footer(printTableContent *const cont, char relkind,
PQExpBufferData buf; PQExpBufferData buf;
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n",
_("Get tablespace information for this relation"));
appendPQExpBuffer(&buf,
"SELECT spcname FROM pg_catalog.pg_tablespace\n" "SELECT spcname FROM pg_catalog.pg_tablespace\n"
"WHERE oid = '%u';", tablespace); "WHERE oid = '%u';", tablespace);
result = PSQLexec(buf.data); result = PSQLexec(buf.data);
@@ -3894,7 +3957,8 @@ describeRoles(const char *pattern, bool verbose, bool showSystem)
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching roles"));
appendPQExpBuffer(&buf,
"SELECT r.rolname, r.rolsuper, r.rolinherit,\n" "SELECT r.rolname, r.rolsuper, r.rolinherit,\n"
" r.rolcreaterole, r.rolcreatedb, r.rolcanlogin,\n" " r.rolcreaterole, r.rolcreatedb, r.rolcanlogin,\n"
" r.rolconnlimit, r.rolvaliduntil"); " r.rolconnlimit, r.rolvaliduntil");
@@ -4033,7 +4097,8 @@ listDbRoleSettings(const char *pattern, const char *pattern2)
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf, "SELECT rolname AS \"%s\", datname AS \"%s\",\n" printfPQExpBuffer(&buf, "/* %s */\n", _("Get per-database and per-role settings"));
appendPQExpBuffer(&buf, "SELECT rolname AS \"%s\", datname AS \"%s\",\n"
"pg_catalog.array_to_string(setconfig, E'\\n') AS \"%s\"\n" "pg_catalog.array_to_string(setconfig, E'\\n') AS \"%s\"\n"
"FROM pg_catalog.pg_db_role_setting s\n" "FROM pg_catalog.pg_db_role_setting s\n"
"LEFT JOIN pg_catalog.pg_database d ON d.oid = setdatabase\n" "LEFT JOIN pg_catalog.pg_database d ON d.oid = setdatabase\n"
@@ -4100,7 +4165,8 @@ describeRoleGrants(const char *pattern, bool showSystem)
printQueryOpt myopt = pset.popt; printQueryOpt myopt = pset.popt;
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching role grants"));
appendPQExpBuffer(&buf,
"SELECT m.rolname AS \"%s\", r.rolname AS \"%s\",\n" "SELECT m.rolname AS \"%s\", r.rolname AS \"%s\",\n"
" pg_catalog.concat_ws(', ',\n", " pg_catalog.concat_ws(', ',\n",
gettext_noop("Role name"), gettext_noop("Role name"),
@@ -4199,7 +4265,8 @@ listTables(const char *tabtypes, const char *pattern, bool verbose, bool showSys
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching relations"));
appendPQExpBuffer(&buf,
"SELECT n.nspname as \"%s\",\n" "SELECT n.nspname as \"%s\",\n"
" c.relname as \"%s\",\n" " c.relname as \"%s\",\n"
" CASE c.relkind" " CASE c.relkind"
@@ -4482,7 +4549,9 @@ listPartitionedTables(const char *reltypes, const char *pattern, bool verbose)
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n",
_("Get matching partitioned relations"));
appendPQExpBuffer(&buf,
"SELECT n.nspname as \"%s\",\n" "SELECT n.nspname as \"%s\",\n"
" c.relname as \"%s\",\n" " c.relname as \"%s\",\n"
" pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"", " pg_catalog.pg_get_userbyid(c.relowner) as \"%s\"",
@@ -4657,7 +4726,8 @@ listLanguages(const char *pattern, bool verbose, bool showSystem)
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching procedural languages"));
appendPQExpBuffer(&buf,
"SELECT l.lanname AS \"%s\",\n" "SELECT l.lanname AS \"%s\",\n"
" pg_catalog.pg_get_userbyid(l.lanowner) as \"%s\",\n" " pg_catalog.pg_get_userbyid(l.lanowner) as \"%s\",\n"
" l.lanpltrusted AS \"%s\"", " l.lanpltrusted AS \"%s\"",
@@ -4733,7 +4803,8 @@ listDomains(const char *pattern, bool verbose, bool showSystem)
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching domains"));
appendPQExpBuffer(&buf,
"SELECT n.nspname as \"%s\",\n" "SELECT n.nspname as \"%s\",\n"
" t.typname as \"%s\",\n" " t.typname as \"%s\",\n"
" pg_catalog.format_type(t.typbasetype, t.typtypmod) as \"%s\",\n" " pg_catalog.format_type(t.typbasetype, t.typtypmod) as \"%s\",\n"
@@ -4818,7 +4889,8 @@ listConversions(const char *pattern, bool verbose, bool showSystem)
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching conversions"));
appendPQExpBuffer(&buf,
"SELECT n.nspname AS \"%s\",\n" "SELECT n.nspname AS \"%s\",\n"
" c.conname AS \"%s\",\n" " c.conname AS \"%s\",\n"
" pg_catalog.pg_encoding_to_char(c.conforencoding) AS \"%s\",\n" " pg_catalog.pg_encoding_to_char(c.conforencoding) AS \"%s\",\n"
@@ -4896,7 +4968,10 @@ describeConfigurationParameters(const char *pattern, bool verbose,
printQueryOpt myopt = pset.popt; printQueryOpt myopt = pset.popt;
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf,
printfPQExpBuffer(&buf, "/* %s */\n",
_("Get matching configuration parameters"));
appendPQExpBuffer(&buf,
"SELECT s.name AS \"%s\", " "SELECT s.name AS \"%s\", "
"pg_catalog.current_setting(s.name) AS \"%s\"", "pg_catalog.current_setting(s.name) AS \"%s\"",
gettext_noop("Parameter"), gettext_noop("Parameter"),
@@ -4976,7 +5051,8 @@ listEventTriggers(const char *pattern, bool verbose)
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching event triggers"));
appendPQExpBuffer(&buf,
"SELECT evtname as \"%s\", " "SELECT evtname as \"%s\", "
"evtevent as \"%s\", " "evtevent as \"%s\", "
"pg_catalog.pg_get_userbyid(e.evtowner) as \"%s\",\n" "pg_catalog.pg_get_userbyid(e.evtowner) as \"%s\",\n"
@@ -5053,7 +5129,9 @@ listExtendedStats(const char *pattern, bool verbose)
} }
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf,
printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching extended statistics"));
appendPQExpBuffer(&buf,
"SELECT \n" "SELECT \n"
"es.stxnamespace::pg_catalog.regnamespace::pg_catalog.text AS \"%s\", \n" "es.stxnamespace::pg_catalog.regnamespace::pg_catalog.text AS \"%s\", \n"
"es.stxname AS \"%s\", \n", "es.stxname AS \"%s\", \n",
@@ -5146,7 +5224,8 @@ listCasts(const char *pattern, bool verbose)
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching casts"));
appendPQExpBuffer(&buf,
"SELECT pg_catalog.format_type(castsource, NULL) AS \"%s\",\n" "SELECT pg_catalog.format_type(castsource, NULL) AS \"%s\",\n"
" pg_catalog.format_type(casttarget, NULL) AS \"%s\",\n", " pg_catalog.format_type(casttarget, NULL) AS \"%s\",\n",
gettext_noop("Source type"), gettext_noop("Source type"),
@@ -5270,7 +5349,8 @@ listCollations(const char *pattern, bool verbose, bool showSystem)
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching collations"));
appendPQExpBuffer(&buf,
"SELECT\n" "SELECT\n"
" n.nspname AS \"%s\",\n" " n.nspname AS \"%s\",\n"
" c.collname AS \"%s\",\n", " c.collname AS \"%s\",\n",
@@ -5393,7 +5473,9 @@ listSchemas(const char *pattern, bool verbose, bool showSystem)
char **footers = NULL; char **footers = NULL;
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf,
printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching schemas"));
appendPQExpBuffer(&buf,
"SELECT n.nspname AS \"%s\",\n" "SELECT n.nspname AS \"%s\",\n"
" pg_catalog.pg_get_userbyid(n.nspowner) AS \"%s\"", " pg_catalog.pg_get_userbyid(n.nspowner) AS \"%s\"",
gettext_noop("Name"), gettext_noop("Name"),
@@ -5436,7 +5518,9 @@ listSchemas(const char *pattern, bool verbose, bool showSystem)
PGresult *result; PGresult *result;
int i; int i;
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n",
_("Get publications that publish this schema"));
appendPQExpBuffer(&buf,
"SELECT pubname \n" "SELECT pubname \n"
"FROM pg_catalog.pg_publication p\n" "FROM pg_catalog.pg_publication p\n"
" JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n" " JOIN pg_catalog.pg_publication_namespace pn ON p.oid = pn.pnpubid\n"
@@ -5516,7 +5600,8 @@ listTSParsers(const char *pattern, bool verbose)
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching text search parsers"));
appendPQExpBuffer(&buf,
"SELECT\n" "SELECT\n"
" n.nspname as \"%s\",\n" " n.nspname as \"%s\",\n"
" p.prsname as \"%s\",\n" " p.prsname as \"%s\",\n"
@@ -5565,7 +5650,8 @@ listTSParsersVerbose(const char *pattern)
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching text search parsers"));
appendPQExpBuffer(&buf,
"SELECT p.oid,\n" "SELECT p.oid,\n"
" n.nspname,\n" " n.nspname,\n"
" p.prsname\n" " p.prsname\n"
@@ -5642,7 +5728,8 @@ describeOneTSParser(const char *oid, const char *nspname, const char *prsname)
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n", _("Get text search parser details"));
appendPQExpBuffer(&buf,
"SELECT '%s' AS \"%s\",\n" "SELECT '%s' AS \"%s\",\n"
" p.prsstart::pg_catalog.regproc AS \"%s\",\n" " p.prsstart::pg_catalog.regproc AS \"%s\",\n"
" pg_catalog.obj_description(p.prsstart, 'pg_proc') as \"%s\"\n" " pg_catalog.obj_description(p.prsstart, 'pg_proc') as \"%s\"\n"
@@ -5710,7 +5797,9 @@ describeOneTSParser(const char *oid, const char *nspname, const char *prsname)
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n",
_("Get text search parser token types"));
appendPQExpBuffer(&buf,
"SELECT t.alias as \"%s\",\n" "SELECT t.alias as \"%s\",\n"
" t.description as \"%s\"\n" " t.description as \"%s\"\n"
"FROM pg_catalog.ts_token_type( '%s'::pg_catalog.oid ) as t\n" "FROM pg_catalog.ts_token_type( '%s'::pg_catalog.oid ) as t\n"
@@ -5760,7 +5849,8 @@ listTSDictionaries(const char *pattern, bool verbose)
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching text search dictionaries"));
appendPQExpBuffer(&buf,
"SELECT\n" "SELECT\n"
" n.nspname as \"%s\",\n" " n.nspname as \"%s\",\n"
" d.dictname as \"%s\",\n", " d.dictname as \"%s\",\n",
@@ -5825,8 +5915,9 @@ listTSTemplates(const char *pattern, bool verbose)
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching text search templates"));
if (verbose) if (verbose)
printfPQExpBuffer(&buf, appendPQExpBuffer(&buf,
"SELECT\n" "SELECT\n"
" n.nspname AS \"%s\",\n" " n.nspname AS \"%s\",\n"
" t.tmplname AS \"%s\",\n" " t.tmplname AS \"%s\",\n"
@@ -5839,7 +5930,7 @@ listTSTemplates(const char *pattern, bool verbose)
gettext_noop("Lexize"), gettext_noop("Lexize"),
gettext_noop("Description")); gettext_noop("Description"));
else else
printfPQExpBuffer(&buf, appendPQExpBuffer(&buf,
"SELECT\n" "SELECT\n"
" n.nspname AS \"%s\",\n" " n.nspname AS \"%s\",\n"
" t.tmplname AS \"%s\",\n" " t.tmplname AS \"%s\",\n"
@@ -5893,7 +5984,8 @@ listTSConfigs(const char *pattern, bool verbose)
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching text search configurations"));
appendPQExpBuffer(&buf,
"SELECT\n" "SELECT\n"
" n.nspname as \"%s\",\n" " n.nspname as \"%s\",\n"
" c.cfgname as \"%s\",\n" " c.cfgname as \"%s\",\n"
@@ -5939,7 +6031,8 @@ listTSConfigsVerbose(const char *pattern)
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching text search configurations"));
appendPQExpBuffer(&buf,
"SELECT c.oid, c.cfgname,\n" "SELECT c.oid, c.cfgname,\n"
" n.nspname,\n" " n.nspname,\n"
" p.prsname,\n" " p.prsname,\n"
@@ -6025,7 +6118,8 @@ describeOneTSConfig(const char *oid, const char *nspname, const char *cfgname,
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n", _("Get text search configuration details"));
appendPQExpBuffer(&buf,
"SELECT\n" "SELECT\n"
" ( SELECT t.alias FROM\n" " ( SELECT t.alias FROM\n"
" pg_catalog.ts_token_type(c.cfgparser) AS t\n" " pg_catalog.ts_token_type(c.cfgparser) AS t\n"
@@ -6093,7 +6187,9 @@ listForeignDataWrappers(const char *pattern, bool verbose)
printQueryOpt myopt = pset.popt; printQueryOpt myopt = pset.popt;
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf,
printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching foreign-data wrappers"));
appendPQExpBuffer(&buf,
"SELECT fdw.fdwname AS \"%s\",\n" "SELECT fdw.fdwname AS \"%s\",\n"
" pg_catalog.pg_get_userbyid(fdw.fdwowner) AS \"%s\",\n" " pg_catalog.pg_get_userbyid(fdw.fdwowner) AS \"%s\",\n"
" fdw.fdwhandler::pg_catalog.regproc AS \"%s\",\n" " fdw.fdwhandler::pg_catalog.regproc AS \"%s\",\n"
@@ -6164,7 +6260,9 @@ listForeignServers(const char *pattern, bool verbose)
printQueryOpt myopt = pset.popt; printQueryOpt myopt = pset.popt;
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf,
printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching foreign servers"));
appendPQExpBuffer(&buf,
"SELECT s.srvname AS \"%s\",\n" "SELECT s.srvname AS \"%s\",\n"
" pg_catalog.pg_get_userbyid(s.srvowner) AS \"%s\",\n" " pg_catalog.pg_get_userbyid(s.srvowner) AS \"%s\",\n"
" f.fdwname AS \"%s\"", " f.fdwname AS \"%s\"",
@@ -6240,7 +6338,9 @@ listUserMappings(const char *pattern, bool verbose)
printQueryOpt myopt = pset.popt; printQueryOpt myopt = pset.popt;
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf,
printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching user mappings"));
appendPQExpBuffer(&buf,
"SELECT um.srvname AS \"%s\",\n" "SELECT um.srvname AS \"%s\",\n"
" um.usename AS \"%s\"", " um.usename AS \"%s\"",
gettext_noop("Server"), gettext_noop("Server"),
@@ -6295,7 +6395,9 @@ listForeignTables(const char *pattern, bool verbose)
printQueryOpt myopt = pset.popt; printQueryOpt myopt = pset.popt;
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf,
printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching foreign tables"));
appendPQExpBuffer(&buf,
"SELECT n.nspname AS \"%s\",\n" "SELECT n.nspname AS \"%s\",\n"
" c.relname AS \"%s\",\n" " c.relname AS \"%s\",\n"
" s.srvname AS \"%s\"", " s.srvname AS \"%s\"",
@@ -6367,7 +6469,9 @@ listExtensions(const char *pattern)
printQueryOpt myopt = pset.popt; printQueryOpt myopt = pset.popt;
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf,
printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching installed extensions"));
appendPQExpBuffer(&buf,
"SELECT e.extname AS \"%s\", " "SELECT e.extname AS \"%s\", "
"e.extversion AS \"%s\", ae.default_version AS \"%s\"," "e.extversion AS \"%s\", ae.default_version AS \"%s\","
"n.nspname AS \"%s\", d.description AS \"%s\"\n" "n.nspname AS \"%s\", d.description AS \"%s\"\n"
@@ -6421,7 +6525,9 @@ listExtensionContents(const char *pattern)
int i; int i;
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf,
printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching installed extensions"));
appendPQExpBuffer(&buf,
"SELECT e.extname, e.oid\n" "SELECT e.extname, e.oid\n"
"FROM pg_catalog.pg_extension e\n"); "FROM pg_catalog.pg_extension e\n");
@@ -6489,7 +6595,9 @@ listOneExtensionContents(const char *extname, const char *oid)
printQueryOpt myopt = pset.popt; printQueryOpt myopt = pset.popt;
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf,
printfPQExpBuffer(&buf, "/* %s */\n", _("Get installed extension's contents"));
appendPQExpBuffer(&buf,
"SELECT pg_catalog.pg_describe_object(classid, objid, 0) AS \"%s\"\n" "SELECT pg_catalog.pg_describe_object(classid, objid, 0) AS \"%s\"\n"
"FROM pg_catalog.pg_depend\n" "FROM pg_catalog.pg_depend\n"
"WHERE refclassid = 'pg_catalog.pg_extension'::pg_catalog.regclass AND refobjid = '%s' AND deptype = 'e'\n" "WHERE refclassid = 'pg_catalog.pg_extension'::pg_catalog.regclass AND refobjid = '%s' AND deptype = 'e'\n"
@@ -6597,7 +6705,8 @@ listPublications(const char *pattern)
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching publications"));
appendPQExpBuffer(&buf,
"SELECT pubname AS \"%s\",\n" "SELECT pubname AS \"%s\",\n"
" pg_catalog.pg_get_userbyid(pubowner) AS \"%s\",\n" " pg_catalog.pg_get_userbyid(pubowner) AS \"%s\",\n"
" puballtables AS \"%s\"", " puballtables AS \"%s\"",
@@ -6748,7 +6857,8 @@ describePublications(const char *pattern)
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n", _("Get details about matching publications"));
appendPQExpBuffer(&buf,
"SELECT oid, pubname,\n" "SELECT oid, pubname,\n"
" pg_catalog.pg_get_userbyid(pubowner) AS owner,\n" " pg_catalog.pg_get_userbyid(pubowner) AS owner,\n"
" puballtables"); " puballtables");
@@ -6884,8 +6994,9 @@ describePublications(const char *pattern)
if (!puballtables) if (!puballtables)
{ {
/* Get the tables for the specified publication */ /* Get the tables for the specified publication */
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n",
"SELECT n.nspname, c.relname"); _("Get tables published by this publication"));
appendPQExpBuffer(&buf, "SELECT n.nspname, c.relname");
if (pset.sversion >= 150000) if (pset.sversion >= 150000)
{ {
appendPQExpBufferStr(&buf, appendPQExpBufferStr(&buf,
@@ -6921,7 +7032,9 @@ describePublications(const char *pattern)
if (pset.sversion >= 150000) if (pset.sversion >= 150000)
{ {
/* Get the schemas for the specified publication */ /* Get the schemas for the specified publication */
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n",
_("Get schemas published by this publication"));
appendPQExpBuffer(&buf,
"SELECT n.nspname\n" "SELECT n.nspname\n"
"FROM pg_catalog.pg_namespace n\n" "FROM pg_catalog.pg_namespace n\n"
" JOIN pg_catalog.pg_publication_namespace pn ON n.oid = pn.pnnspid\n" " JOIN pg_catalog.pg_publication_namespace pn ON n.oid = pn.pnnspid\n"
@@ -6937,7 +7050,9 @@ describePublications(const char *pattern)
if (pset.sversion >= 190000) if (pset.sversion >= 190000)
{ {
/* Get tables in the EXCEPT clause for this publication */ /* Get tables in the EXCEPT clause for this publication */
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n",
_("Get tables excluded by this publication"));
appendPQExpBuffer(&buf,
"SELECT n.nspname || '.' || c.relname\n" "SELECT n.nspname || '.' || c.relname\n"
"FROM pg_catalog.pg_class c\n" "FROM pg_catalog.pg_class c\n"
" JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n" " JOIN pg_catalog.pg_namespace n ON n.oid = c.relnamespace\n"
@@ -6997,7 +7112,8 @@ describeSubscriptions(const char *pattern, bool verbose)
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching subscriptions"));
appendPQExpBuffer(&buf,
"SELECT subname AS \"%s\"\n" "SELECT subname AS \"%s\"\n"
", pg_catalog.pg_get_userbyid(subowner) AS \"%s\"\n" ", pg_catalog.pg_get_userbyid(subowner) AS \"%s\"\n"
", subenabled AS \"%s\"\n" ", subenabled AS \"%s\"\n"
@@ -7166,7 +7282,8 @@ listOperatorClasses(const char *access_method_pattern,
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching operator classes"));
appendPQExpBuffer(&buf,
"SELECT\n" "SELECT\n"
" am.amname AS \"%s\",\n" " am.amname AS \"%s\",\n"
" pg_catalog.format_type(c.opcintype, NULL) AS \"%s\",\n" " pg_catalog.format_type(c.opcintype, NULL) AS \"%s\",\n"
@@ -7267,7 +7384,8 @@ listOperatorFamilies(const char *access_method_pattern,
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching operator families"));
appendPQExpBuffer(&buf,
"SELECT\n" "SELECT\n"
" am.amname AS \"%s\",\n" " am.amname AS \"%s\",\n"
" CASE\n" " CASE\n"
@@ -7357,7 +7475,8 @@ listOpFamilyOperators(const char *access_method_pattern,
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n", _("Get operators of matching operator families"));
appendPQExpBuffer(&buf,
"SELECT\n" "SELECT\n"
" am.amname AS \"%s\",\n" " am.amname AS \"%s\",\n"
" CASE\n" " CASE\n"
@@ -7463,7 +7582,9 @@ listOpFamilyFunctions(const char *access_method_pattern,
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n",
_("Get support functions of matching operator families"));
appendPQExpBuffer(&buf,
"SELECT\n" "SELECT\n"
" am.amname AS \"%s\",\n" " am.amname AS \"%s\",\n"
" CASE\n" " CASE\n"
@@ -7549,7 +7670,8 @@ listLargeObjects(bool verbose)
initPQExpBuffer(&buf); initPQExpBuffer(&buf);
printfPQExpBuffer(&buf, printfPQExpBuffer(&buf, "/* %s */\n", _("Get large objects"));
appendPQExpBuffer(&buf,
"SELECT oid as \"%s\",\n" "SELECT oid as \"%s\",\n"
" pg_catalog.pg_get_userbyid(lomowner) as \"%s\",\n ", " pg_catalog.pg_get_userbyid(lomowner) as \"%s\",\n ",
gettext_noop("ID"), gettext_noop("ID"),