Hi,

Looks like we agree on the three-way rule, with the API Tom suggested.

v3 attached, done the way Tom suggested. addQueryComment() uses the
translation only if it is plain ASCII, or if gettext's output
encoding, client_encoding and server_encoding are known to match.
Otherwise it uses the English label.

> Matching all three encodings may not be sufficient, since, e.g.,
> OUTPUT_CHARSET can also affect the locale encoding?

Yes. psql never calls bind_textdomain_codeset(), so OUTPUT_CHARSET is
the only override. With all three UTF8 and OUTPUT_CHARSET=EUC-JP,
19rc1 fails with invalid byte sequence. v3 uses English whenever
OUTPUT_CHARSET is set.

> I'm also not sure whether matching all three is sufficient on Windows.

I can’t test there. psql and libintl work out the code page in different
ways on
Windows, and I could not convince myself they always agree. So on Windows
v3 uses the English label whenever the translation is not plain ASCII.

We may lose a little since the CJK code pages map to SJIS, GBK, BIG5
and UHC, which can never be server_encoding.

Thanks,
Shihao
From 9d4cd17ffc985bfea2e91e9888d46bfc755f38cd Mon Sep 17 00:00:00 2001
From: shihao zhong <[email protected]>
Date: Tue, 13 Oct 2026 23:14:28 -0400
Subject: [PATCH v3] psql: Fall back to English for unsafe hidden query labels.

Since 41d69e6dcca the labels are translated, and the server rejects the
query when the translation is not valid in the client or database
encoding. Add addQueryComment(), which uses a non-ASCII translation
only when gettext's output, client and server encodings are known to
match.
---
 src/bin/psql/command.c  |   8 +-
 src/bin/psql/common.c   |  40 +++++++++
 src/bin/psql/common.h   |   1 +
 src/bin/psql/describe.c | 191 +++++++++++++++++-----------------------
 4 files changed, 125 insertions(+), 115 deletions(-)

diff --git a/src/bin/psql/command.c b/src/bin/psql/command.c
index 73c69a1c258..e8ad0a71e8c 100644
--- a/src/bin/psql/command.c
+++ b/src/bin/psql/command.c
@@ -6222,7 +6222,7 @@ lookup_object_oid(EditableObjectType obj_type, const char 
*desc,
                         * query to retrieve the function's OID using a cast to 
regproc or
                         * regprocedure (as appropriate).
                         */
-                       printfPQExpBuffer(query, "/* %s */\n", _("Get 
function's OID"));
+                       addQueryComment(query, gettext_noop("Get function's 
OID"));
                        appendPQExpBufferStr(query, "SELECT ");
                        appendStringLiteralConn(query, desc, pset.db);
                        appendPQExpBuffer(query, 
"::pg_catalog.%s::pg_catalog.oid",
@@ -6236,7 +6236,7 @@ lookup_object_oid(EditableObjectType obj_type, const char 
*desc,
                         * this code doesn't check if the relation is actually 
a view.
                         * We'll detect that in get_create_object_cmd().
                         */
-                       printfPQExpBuffer(query, "/* %s */\n", _("Get view's 
OID"));
+                       addQueryComment(query, gettext_noop("Get view's OID"));
                        appendPQExpBufferStr(query, "SELECT ");
                        appendStringLiteralConn(query, desc, pset.db);
                        appendPQExpBufferStr(query, 
"::pg_catalog.regclass::pg_catalog.oid");
@@ -6278,7 +6278,7 @@ get_create_object_cmd(EditableObjectType obj_type, Oid 
oid,
        switch (obj_type)
        {
                case EditableFunction:
-                       printfPQExpBuffer(query, "/* %s */\n", _("Get 
function's definition"));
+                       addQueryComment(query, gettext_noop("Get function's 
definition"));
                        appendPQExpBuffer(query,
                                                          "SELECT 
pg_catalog.pg_get_functiondef(%u)",
                                                          oid);
@@ -6298,7 +6298,7 @@ get_create_object_cmd(EditableObjectType obj_type, Oid 
oid,
                         * separately.  Materialized views (introduced in 9.3) 
may have
                         * arbitrary storage parameter reloptions.
                         */
-                       printfPQExpBuffer(query, "/* %s */\n", _("Get view's 
definition and details"));
+                       addQueryComment(query, gettext_noop("Get view's 
definition and details"));
                        if (pset.sversion >= 90400)
                        {
                                appendPQExpBuffer(query,
diff --git a/src/bin/psql/common.c b/src/bin/psql/common.c
index 305c423e196..041c1533348 100644
--- a/src/bin/psql/common.c
+++ b/src/bin/psql/common.c
@@ -22,6 +22,7 @@
 #include "command.h"
 #include "common.h"
 #include "common/logging.h"
+#include "common/string.h"
 #include "copy.h"
 #include "crosstabview.h"
 #include "fe_utils/cancel.h"
@@ -643,6 +644,45 @@ PrintTiming(double elapsed_msec)
 }
 
 
+/*
+ * addQueryComment
+ *
+ * Reset buf and start it with a comment holding label, which must be marked
+ * with gettext_noop().  The comment shows up in the -E output and in the
+ * server log.
+ *
+ * The server converts the query from the client encoding to the database
+ * encoding, so a translation that is not plain ASCII is only used when we
+ * know it is in an encoding that survives that.  gettext produces it in the
+ * encoding of LC_CTYPE, unless OUTPUT_CHARSET overrides it.  On Windows the
+ * encoding gettext uses is not certain to match what we would compute, so
+ * don't try there.  Otherwise use the English label.
+ */
+void
+addQueryComment(PQExpBuffer buf, const char *label)
+{
+       const char *translated = _(label);
+
+       if (translated != label && !pg_is_ascii(translated))
+       {
+#ifndef WIN32
+               const char *server_enc = PQparameterStatus(pset.db, 
"server_encoding");
+               int                     client_enc = PQclientEncoding(pset.db);
+
+               if (getenv("OUTPUT_CHARSET") != NULL ||
+                       server_enc == NULL ||
+                       pg_char_to_encoding(server_enc) != client_enc ||
+                       pg_get_encoding_from_locale(NULL, false) != client_enc)
+                       translated = label;
+#else
+               translated = label;
+#endif
+       }
+
+       printfPQExpBuffer(buf, "/* %s */\n", translated);
+}
+
+
 /*
  * PSQLexec
  *
diff --git a/src/bin/psql/common.h b/src/bin/psql/common.h
index d4b99b42331..eb8c2e7668a 100644
--- a/src/bin/psql/common.h
+++ b/src/bin/psql/common.h
@@ -31,6 +31,7 @@ extern void psql_setup_cancel_handler(void);
 
 extern void SetShellResultVariables(int wait_result);
 
+extern void addQueryComment(PQExpBuffer buf, const char *label);
 extern PGresult *PSQLexec(const char *query);
 extern int     PSQLexecWatch(const char *query, const printQueryOpt *opt, FILE 
*printQueryFout, int min_rows);
 
diff --git a/src/bin/psql/describe.c b/src/bin/psql/describe.c
index 5b8c813f687..c1afbde420c 100644
--- a/src/bin/psql/describe.c
+++ b/src/bin/psql/describe.c
@@ -83,7 +83,7 @@ describeAggregates(const char *pattern, bool verbose, bool 
showSystem)
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching aggregates"));
+       addQueryComment(&buf, gettext_noop("Get matching aggregates"));
        appendPQExpBuffer(&buf,
                                          "SELECT n.nspname as \"%s\",\n"
                                          "  p.proname AS \"%s\",\n"
@@ -165,7 +165,7 @@ describeAccessMethods(const char *pattern, bool verbose)
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching access methods"));
+       addQueryComment(&buf, gettext_noop("Get matching access methods"));
        appendPQExpBuffer(&buf,
                                          "SELECT amname AS \"%s\",\n"
                                          "  CASE amtype"
@@ -229,7 +229,7 @@ describeTablespaces(const char *pattern, bool verbose)
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching tablespaces"));
+       addQueryComment(&buf, gettext_noop("Get matching tablespaces"));
        appendPQExpBuffer(&buf,
                                          "SELECT spcname AS \"%s\",\n"
                                          "  
pg_catalog.pg_get_userbyid(spcowner) AS \"%s\",\n"
@@ -340,7 +340,7 @@ describeFunctions(const char *functypes, const char 
*func_pattern,
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching functions"));
+       addQueryComment(&buf, gettext_noop("Get matching functions"));
        appendPQExpBuffer(&buf,
                                          "SELECT n.nspname as \"%s\",\n"
                                          "  p.proname as \"%s\",\n",
@@ -648,7 +648,7 @@ describeTypes(const char *pattern, bool verbose, bool 
showSystem)
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching types"));
+       addQueryComment(&buf, gettext_noop("Get matching types"));
        appendPQExpBuffer(&buf,
                                          "SELECT n.nspname as \"%s\",\n"
                                          "  pg_catalog.format_type(t.oid, 
NULL) AS \"%s\",\n",
@@ -823,7 +823,7 @@ describeOperators(const char *oper_pattern,
         * to pre-v14 servers.
         */
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching operators"));
+       addQueryComment(&buf, gettext_noop("Get matching operators"));
        appendPQExpBuffer(&buf,
                                          "SELECT n.nspname as \"%s\",\n"
                                          "  o.oprname AS \"%s\",\n"
@@ -957,7 +957,7 @@ listAllDbs(const char *pattern, bool verbose)
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching databases"));
+       addQueryComment(&buf, gettext_noop("Get matching databases"));
        appendPQExpBuffer(&buf,
                                          "SELECT\n"
                                          "  d.datname as \"%s\",\n"
@@ -1070,8 +1070,7 @@ permissionsList(const char *pattern, bool showSystem)
        /*
         * we ignore indexes and toast tables since they have no meaningful 
rights
         */
-       printfPQExpBuffer(&buf, "/* %s */\n",
-                                         _("Get access privileges of matching 
relations"));
+       addQueryComment(&buf, gettext_noop("Get access privileges of matching 
relations"));
        appendPQExpBuffer(&buf,
                                          "SELECT n.nspname as \"%s\",\n"
                                          "  c.relname as \"%s\",\n"
@@ -1233,7 +1232,7 @@ listDefaultACLs(const char *pattern)
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching default ACLs"));
+       addQueryComment(&buf, gettext_noop("Get matching default ACLs"));
        appendPQExpBuffer(&buf,
                                          "SELECT 
pg_catalog.pg_get_userbyid(d.defaclrole) AS \"%s\",\n"
                                          "  n.nspname AS \"%s\",\n"
@@ -1315,7 +1314,7 @@ objectDescription(const char *pattern, bool showSystem)
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching object 
comments"));
+       addQueryComment(&buf, gettext_noop("Get matching object comments"));
        appendPQExpBuffer(&buf,
                                          "SELECT DISTINCT tt.nspname AS 
\"%s\", tt.name AS \"%s\", tt.object AS \"%s\", d.description AS \"%s\"\n"
                                          "FROM (\n",
@@ -1508,8 +1507,7 @@ describeTableDetails(const char *pattern, bool verbose, 
bool showSystem)
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n",
-                                         _("Get matching relations to 
describe"));
+       addQueryComment(&buf, gettext_noop("Get matching relations to 
describe"));
        appendPQExpBufferStr(&buf,
                                                 "SELECT c.oid,\n"
                                                 "  n.nspname,\n"
@@ -1646,8 +1644,7 @@ describeOneTableDetails(const char *schemaname,
        initPQExpBuffer(&tmpbuf);
 
        /* Get general table info */
-       printfPQExpBuffer(&buf, "/* %s */\n",
-                                         _("Get general information about one 
relation"));
+       addQueryComment(&buf, gettext_noop("Get general information about one 
relation"));
        if (pset.sversion >= 120000)
        {
                appendPQExpBuffer(&buf,
@@ -1780,7 +1777,7 @@ describeOneTableDetails(const char *schemaname,
                printQueryOpt myopt = pset.popt;
                char       *footers[3] = {NULL, NULL, NULL};
 
-               printfPQExpBuffer(&buf, "/* %s */\n", _("Get sequence 
information"));
+               addQueryComment(&buf, gettext_noop("Get sequence information"));
                if (pset.sversion >= 100000)
                {
                        appendPQExpBuffer(&buf,
@@ -1834,8 +1831,7 @@ describeOneTableDetails(const char *schemaname,
                        goto error_return;
 
                /* Get the column that owns this sequence */
-               printfPQExpBuffer(&buf, "/* %s */\n",
-                                                 _("Get the column that owns 
this sequence"));
+               addQueryComment(&buf, gettext_noop("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(attname),"
@@ -1880,8 +1876,7 @@ describeOneTableDetails(const char *schemaname,
                /* Print any publications */
                if (pset.sversion >= 190000)
                {
-                       printfPQExpBuffer(&buf, "/* %s */\n",
-                                                         _("Get publications 
containing this sequence"));
+                       addQueryComment(&buf, gettext_noop("Get publications 
containing this sequence"));
                        appendPQExpBuffer(&buf, "SELECT pubname FROM 
pg_catalog.pg_publication p"
                                                          "\nWHERE 
p.puballsequences"
                                                          "\n AND 
pg_catalog.pg_relation_is_publishable('%s')"
@@ -1951,8 +1946,7 @@ describeOneTableDetails(const char *schemaname,
         * duplicative test logic below.
         */
        cols = 0;
-       printfPQExpBuffer(&buf, "/* %s */\n",
-                                         _("Get per-column information for one 
relation"));
+       addQueryComment(&buf, gettext_noop("Get per-column information for one 
relation"));
        appendPQExpBufferStr(&buf, "SELECT a.attname");
        attname_col = cols++;
        appendPQExpBufferStr(&buf, ",\n  pg_catalog.format_type(a.atttypid, 
a.atttypmod)");
@@ -2255,8 +2249,7 @@ describeOneTableDetails(const char *schemaname,
                /* Footer information for a partition child table */
                PGresult   *result;
 
-               printfPQExpBuffer(&buf, "/* %s */\n",
-                                                 _("Get partitioning 
information for this partition"));
+               addQueryComment(&buf, gettext_noop("Get partitioning 
information for this partition"));
                appendPQExpBufferStr(&buf,
                                                         "SELECT 
inhparent::pg_catalog.regclass,\n"
                                                         "  
pg_catalog.pg_get_expr(c.relpartbound, c.oid),\n  ");
@@ -2312,8 +2305,7 @@ describeOneTableDetails(const char *schemaname,
                /* Footer information for a partitioned table (partitioning 
parent) */
                PGresult   *result;
 
-               printfPQExpBuffer(&buf, "/* %s */\n",
-                                                 _("Get partitioning 
information for this table"));
+               addQueryComment(&buf, gettext_noop("Get partitioning 
information for this table"));
                appendPQExpBuffer(&buf,
                                                  "SELECT 
pg_catalog.pg_get_partkeydef('%s'::pg_catalog.oid);",
                                                  oid);
@@ -2336,8 +2328,7 @@ describeOneTableDetails(const char *schemaname,
                /* For a TOAST table, print name of owning table */
                PGresult   *result;
 
-               printfPQExpBuffer(&buf, "/* %s */\n",
-                                                 _("Get the table that owns 
this TOAST table"));
+               addQueryComment(&buf, gettext_noop("Get the table that owns 
this TOAST table"));
                appendPQExpBuffer(&buf,
                                                  "SELECT n.nspname, 
c.relname\n"
                                                  "FROM pg_catalog.pg_class c"
@@ -2366,7 +2357,7 @@ describeOneTableDetails(const char *schemaname,
                /* Footer information about an index */
                PGresult   *result;
 
-               printfPQExpBuffer(&buf, "/* %s */\n", _("Get index details"));
+               addQueryComment(&buf, gettext_noop("Get index details"));
                appendPQExpBufferStr(&buf,
                                                         "SELECT i.indisunique, 
i.indisprimary, i.indisclustered, "
                                                         "i.indisvalid,\n"
@@ -2488,7 +2479,7 @@ describeOneTableDetails(const char *schemaname,
                /* print indexes */
                if (tableinfo.hasindex)
                {
-                       printfPQExpBuffer(&buf, "/* %s */\n", _("Get indexes 
for this table"));
+                       addQueryComment(&buf, gettext_noop("Get indexes for 
this table"));
                        appendPQExpBufferStr(&buf,
                                                                 "SELECT 
c2.relname, i.indisprimary, i.indisunique, "
                                                                 
"i.indisclustered, i.indisvalid, "
@@ -2593,8 +2584,7 @@ describeOneTableDetails(const char *schemaname,
                /* print table (and column) check constraints */
                if (tableinfo.checks)
                {
-                       printfPQExpBuffer(&buf, "/* %s */\n",
-                                                         _("Get check 
constraints for this table"));
+                       addQueryComment(&buf, gettext_noop("Get check 
constraints for this table"));
                        appendPQExpBuffer(&buf,
                                                          "SELECT r.conname, "
                                                          
"pg_catalog.pg_get_constraintdef(r.oid, true)\n"
@@ -2626,8 +2616,7 @@ describeOneTableDetails(const char *schemaname,
                }
 
                /* Print foreign-key constraints */
-               printfPQExpBuffer(&buf, "/* %s */\n",
-                                                 _("Get foreign key 
constraints for this table"));
+               addQueryComment(&buf, gettext_noop("Get foreign key constraints 
for this table"));
                if (pset.sversion >= 120000 &&
                        (tableinfo.ispartition || tableinfo.relkind == 
RELKIND_PARTITIONED_TABLE))
                {
@@ -2698,8 +2687,7 @@ describeOneTableDetails(const char *schemaname,
                PQclear(result);
 
                /* print incoming foreign-key references */
-               printfPQExpBuffer(&buf, "/* %s */\n",
-                                                 _("Get foreign keys 
referencing this table"));
+               addQueryComment(&buf, gettext_noop("Get foreign keys 
referencing this table"));
                if (pset.sversion >= 120000)
                {
                        appendPQExpBuffer(&buf,
@@ -2751,8 +2739,7 @@ describeOneTableDetails(const char *schemaname,
                /* print any row-level policies */
                if (pset.sversion >= 90500)
                {
-                       printfPQExpBuffer(&buf, "/* %s */\n",
-                                                         _("Get row-level 
policies for this table"));
+                       addQueryComment(&buf, gettext_noop("Get row-level 
policies for this table"));
                        appendPQExpBufferStr(&buf, "SELECT pol.polname,");
                        if (pset.sversion >= 100000)
                                appendPQExpBufferStr(&buf,
@@ -2835,8 +2822,7 @@ describeOneTableDetails(const char *schemaname,
                /* print any extended statistics */
                if (pset.sversion >= 140000)
                {
-                       printfPQExpBuffer(&buf, "/* %s */\n",
-                                                         _("Get extended 
statistics for this table"));
+                       addQueryComment(&buf, gettext_noop("Get extended 
statistics for this table"));
                        appendPQExpBuffer(&buf,
                                                          "SELECT oid, "
                                                          
"stxrelid::pg_catalog.regclass, "
@@ -2935,8 +2921,7 @@ describeOneTableDetails(const char *schemaname,
                }
                else if (pset.sversion >= 100000)
                {
-                       printfPQExpBuffer(&buf, "/* %s */\n",
-                                                         _("Get extended 
statistics for this table"));
+                       addQueryComment(&buf, gettext_noop("Get extended 
statistics for this table"));
                        appendPQExpBufferStr(&buf,
                                                                 "SELECT oid, "
                                                                 
"stxrelid::pg_catalog.regclass, "
@@ -3016,8 +3001,7 @@ describeOneTableDetails(const char *schemaname,
                /* print rules */
                if (tableinfo.hasrules && tableinfo.relkind != RELKIND_MATVIEW)
                {
-                       printfPQExpBuffer(&buf, "/* %s */\n",
-                                                         _("Get rules for this 
relation"));
+                       addQueryComment(&buf, gettext_noop("Get rules for this 
relation"));
                        appendPQExpBuffer(&buf,
                                                          "SELECT r.rulename, 
trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true)), "
                                                          "ev_enabled\n"
@@ -3101,8 +3085,7 @@ describeOneTableDetails(const char *schemaname,
                /* print any publications */
                if (pset.sversion >= 100000)
                {
-                       printfPQExpBuffer(&buf, "/* %s */\n",
-                                                         _("Get publications 
that publish this table"));
+                       addQueryComment(&buf, gettext_noop("Get publications 
that publish this table"));
                        if (pset.sversion >= 150000)
                        {
                                appendPQExpBuffer(&buf,
@@ -3215,8 +3198,7 @@ describeOneTableDetails(const char *schemaname,
                /* Print publications where the table is in the EXCEPT clause */
                if (pset.sversion >= 190000)
                {
-                       printfPQExpBuffer(&buf, "/* %s */\n",
-                                                         _("Get publications 
that exclude this table"));
+                       addQueryComment(&buf, gettext_noop("Get publications 
that exclude this table"));
                        appendPQExpBuffer(&buf,
                                                          "SELECT pubname\n"
                                                          "FROM 
pg_catalog.pg_publication p\n"
@@ -3249,8 +3231,7 @@ describeOneTableDetails(const char *schemaname,
                 */
                if (verbose)
                {
-                       printfPQExpBuffer(&buf, "/* %s */\n",
-                                                         _("Get not-null 
constraints for this table"));
+                       addQueryComment(&buf, gettext_noop("Get not-null 
constraints for this table"));
                        appendPQExpBuffer(&buf,
                                                          "SELECT c.conname, 
a.attname, c.connoinherit,\n"
                                                          "  c.conislocal, 
c.coninhcount <> 0,\n"
@@ -3300,7 +3281,7 @@ describeOneTableDetails(const char *schemaname,
        {
                PGresult   *result;
 
-               printfPQExpBuffer(&buf, "/* %s */\n", _("Get view's 
definition"));
+               addQueryComment(&buf, gettext_noop("Get view's definition"));
                appendPQExpBuffer(&buf,
                                                  "SELECT 
pg_catalog.pg_get_viewdef('%s'::pg_catalog.oid, true);",
                                                  oid);
@@ -3325,7 +3306,7 @@ describeOneTableDetails(const char *schemaname,
                /* print rules */
                if (tableinfo.hasrules)
                {
-                       printfPQExpBuffer(&buf, "/* %s */\n", _("Get rules for 
this view"));
+                       addQueryComment(&buf, gettext_noop("Get rules for this 
view"));
                        appendPQExpBuffer(&buf,
                                                          "SELECT r.rulename, 
trim(trailing ';' from pg_catalog.pg_get_ruledef(r.oid, true))\n"
                                                          "FROM 
pg_catalog.pg_rewrite r\n"
@@ -3363,8 +3344,7 @@ describeOneTableDetails(const char *schemaname,
                PGresult   *result;
                int                     tuples;
 
-               printfPQExpBuffer(&buf, "/* %s */\n",
-                                                 _("Get triggers for this 
relation"));
+               addQueryComment(&buf, gettext_noop("Get triggers for this 
relation"));
                appendPQExpBufferStr(&buf,
                                                         "SELECT t.tgname, "
                                                         
"pg_catalog.pg_get_triggerdef(t.oid, true), "
@@ -3548,8 +3528,7 @@ describeOneTableDetails(const char *schemaname,
                        char       *ftoptions;
 
                        /* Footer information about foreign table */
-                       printfPQExpBuffer(&buf, "/* %s */\n",
-                                                         _("Get foreign server 
for this table"));
+                       addQueryComment(&buf, gettext_noop("Get foreign server 
for this table"));
                        appendPQExpBuffer(&buf,
                                                          "SELECT s.srvname,\n"
                                                          "  
pg_catalog.array_to_string(ARRAY(\n"
@@ -3585,8 +3564,7 @@ describeOneTableDetails(const char *schemaname,
                }
 
                /* print tables inherited from (exclude partitioned parents) */
-               printfPQExpBuffer(&buf, "/* %s */\n",
-                                                 _("Get inheritance parent 
tables"));
+               addQueryComment(&buf, gettext_noop("Get inheritance parent 
tables"));
                appendPQExpBuffer(&buf,
                                                  "SELECT 
c.oid::pg_catalog.regclass\n"
                                                  "FROM pg_catalog.pg_class c, 
pg_catalog.pg_inherits i\n"
@@ -3621,7 +3599,7 @@ describeOneTableDetails(const char *schemaname,
                }
 
                /* print child tables (with additional info if partitions) */
-               printfPQExpBuffer(&buf, "/* %s */\n", _("Get child tables"));
+               addQueryComment(&buf, gettext_noop("Get child tables"));
                if (pset.sversion >= 140000)
                        appendPQExpBuffer(&buf,
                                                          "SELECT 
c.oid::pg_catalog.regclass, c.relkind,"
@@ -3815,8 +3793,7 @@ add_tablespace_footer(printTableContent *const cont, char 
relkind,
                        PQExpBufferData buf;
 
                        initPQExpBuffer(&buf);
-                       printfPQExpBuffer(&buf, "/* %s */\n",
-                                                         _("Get tablespace 
information for this relation"));
+                       addQueryComment(&buf, gettext_noop("Get tablespace 
information for this relation"));
                        appendPQExpBuffer(&buf,
                                                          "SELECT spcname FROM 
pg_catalog.pg_tablespace\n"
                                                          "WHERE oid = '%u';", 
tablespace);
@@ -3878,7 +3855,7 @@ describeRoles(const char *pattern, bool verbose, bool 
showSystem)
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching roles"));
+       addQueryComment(&buf, gettext_noop("Get matching roles"));
        appendPQExpBufferStr(&buf,
                                                 "SELECT r.rolname, r.rolsuper, 
r.rolinherit,\n"
                                                 "  r.rolcreaterole, 
r.rolcreatedb, r.rolcanlogin,\n"
@@ -4018,7 +3995,7 @@ listDbRoleSettings(const char *pattern, const char 
*pattern2)
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get per-database and per-role 
settings"));
+       addQueryComment(&buf, gettext_noop("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"
                                          "FROM pg_catalog.pg_db_role_setting 
s\n"
@@ -4086,7 +4063,7 @@ describeRoleGrants(const char *pattern, bool showSystem)
        printQueryOpt myopt = pset.popt;
 
        initPQExpBuffer(&buf);
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching role grants"));
+       addQueryComment(&buf, gettext_noop("Get matching role grants"));
        appendPQExpBuffer(&buf,
                                          "SELECT m.rolname AS \"%s\", 
r.rolname AS \"%s\",\n"
                                          "  pg_catalog.concat_ws(', ',\n",
@@ -4184,7 +4161,7 @@ listTables(const char *tabtypes, const char *pattern, 
bool verbose, bool showSys
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching relations"));
+       addQueryComment(&buf, gettext_noop("Get matching relations"));
        appendPQExpBuffer(&buf,
                                          "SELECT n.nspname as \"%s\",\n"
                                          "  c.relname as \"%s\",\n"
@@ -4458,8 +4435,7 @@ listPartitionedTables(const char *reltypes, const char 
*pattern, bool verbose)
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n",
-                                         _("Get matching partitioned 
relations"));
+       addQueryComment(&buf, gettext_noop("Get matching partitioned 
relations"));
        appendPQExpBuffer(&buf,
                                          "SELECT n.nspname as \"%s\",\n"
                                          "  c.relname as \"%s\",\n"
@@ -4635,7 +4611,7 @@ listLanguages(const char *pattern, bool verbose, bool 
showSystem)
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching procedural 
languages"));
+       addQueryComment(&buf, gettext_noop("Get matching procedural 
languages"));
        appendPQExpBuffer(&buf,
                                          "SELECT l.lanname AS \"%s\",\n"
                                          "       
pg_catalog.pg_get_userbyid(l.lanowner) as \"%s\",\n"
@@ -4712,7 +4688,7 @@ listDomains(const char *pattern, bool verbose, bool 
showSystem)
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching domains"));
+       addQueryComment(&buf, gettext_noop("Get matching domains"));
        appendPQExpBuffer(&buf,
                                          "SELECT n.nspname as \"%s\",\n"
                                          "       t.typname as \"%s\",\n"
@@ -4798,7 +4774,7 @@ listConversions(const char *pattern, bool verbose, bool 
showSystem)
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching conversions"));
+       addQueryComment(&buf, gettext_noop("Get matching conversions"));
        appendPQExpBuffer(&buf,
                                          "SELECT n.nspname AS \"%s\",\n"
                                          "       c.conname AS \"%s\",\n"
@@ -4878,8 +4854,7 @@ describeConfigurationParameters(const char *pattern, bool 
verbose,
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n",
-                                         _("Get matching configuration 
parameters"));
+       addQueryComment(&buf, gettext_noop("Get matching configuration 
parameters"));
        appendPQExpBuffer(&buf,
                                          "SELECT s.name AS \"%s\", "
                                          "pg_catalog.current_setting(s.name) 
AS \"%s\"",
@@ -4960,7 +4935,7 @@ listEventTriggers(const char *pattern, bool verbose)
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching event triggers"));
+       addQueryComment(&buf, gettext_noop("Get matching event triggers"));
        appendPQExpBuffer(&buf,
                                          "SELECT evtname as \"%s\", "
                                          "evtevent as \"%s\", "
@@ -5039,7 +5014,7 @@ listExtendedStats(const char *pattern, bool verbose)
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching extended 
statistics"));
+       addQueryComment(&buf, gettext_noop("Get matching extended statistics"));
        appendPQExpBuffer(&buf,
                                          "SELECT \n"
                                          
"es.stxnamespace::pg_catalog.regnamespace::pg_catalog.text AS \"%s\", \n"
@@ -5133,7 +5108,7 @@ listCasts(const char *pattern, bool verbose)
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching casts"));
+       addQueryComment(&buf, gettext_noop("Get matching casts"));
        appendPQExpBuffer(&buf,
                                          "SELECT 
pg_catalog.format_type(castsource, NULL) AS \"%s\",\n"
                                          "       
pg_catalog.format_type(casttarget, NULL) AS \"%s\",\n",
@@ -5258,7 +5233,7 @@ listCollations(const char *pattern, bool verbose, bool 
showSystem)
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching collations"));
+       addQueryComment(&buf, gettext_noop("Get matching collations"));
        appendPQExpBuffer(&buf,
                                          "SELECT\n"
                                          "  n.nspname AS \"%s\",\n"
@@ -5383,7 +5358,7 @@ listSchemas(const char *pattern, bool verbose, bool 
showSystem)
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching schemas"));
+       addQueryComment(&buf, gettext_noop("Get matching schemas"));
        appendPQExpBuffer(&buf,
                                          "SELECT n.nspname AS \"%s\",\n"
                                          "  
pg_catalog.pg_get_userbyid(n.nspowner) AS \"%s\"",
@@ -5427,8 +5402,7 @@ listSchemas(const char *pattern, bool verbose, bool 
showSystem)
                PGresult   *result;
                int                     i;
 
-               printfPQExpBuffer(&buf, "/* %s */\n",
-                                                 _("Get publications that 
publish this schema"));
+               addQueryComment(&buf, gettext_noop("Get publications that 
publish this schema"));
                appendPQExpBuffer(&buf,
                                                  "SELECT pubname \n"
                                                  "FROM 
pg_catalog.pg_publication p\n"
@@ -5509,7 +5483,7 @@ listTSParsers(const char *pattern, bool verbose)
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching text search 
parsers"));
+       addQueryComment(&buf, gettext_noop("Get matching text search parsers"));
        appendPQExpBuffer(&buf,
                                          "SELECT\n"
                                          "  n.nspname as \"%s\",\n"
@@ -5559,7 +5533,7 @@ listTSParsersVerbose(const char *pattern)
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching text search 
parsers"));
+       addQueryComment(&buf, gettext_noop("Get matching text search parsers"));
        appendPQExpBufferStr(&buf,
                                                 "SELECT p.oid,\n"
                                                 "  n.nspname,\n"
@@ -5637,7 +5611,7 @@ describeOneTSParser(const char *oid, const char *nspname, 
const char *prsname)
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get text search parser 
details"));
+       addQueryComment(&buf, gettext_noop("Get text search parser details"));
        appendPQExpBuffer(&buf,
                                          "SELECT '%s' AS \"%s\",\n"
                                          "   p.prsstart::pg_catalog.regproc AS 
\"%s\",\n"
@@ -5706,8 +5680,7 @@ describeOneTSParser(const char *oid, const char *nspname, 
const char *prsname)
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n",
-                                         _("Get text search parser token 
types"));
+       addQueryComment(&buf, gettext_noop("Get text search parser token 
types"));
        appendPQExpBuffer(&buf,
                                          "SELECT t.alias as \"%s\",\n"
                                          "  t.description as \"%s\"\n"
@@ -5758,7 +5731,7 @@ listTSDictionaries(const char *pattern, bool verbose)
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching text search 
dictionaries"));
+       addQueryComment(&buf, gettext_noop("Get matching text search 
dictionaries"));
        appendPQExpBuffer(&buf,
                                          "SELECT\n"
                                          "  n.nspname as \"%s\",\n"
@@ -5824,7 +5797,7 @@ listTSTemplates(const char *pattern, bool verbose)
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching text search 
templates"));
+       addQueryComment(&buf, gettext_noop("Get matching text search 
templates"));
        if (verbose)
                appendPQExpBuffer(&buf,
                                                  "SELECT\n"
@@ -5893,7 +5866,7 @@ listTSConfigs(const char *pattern, bool verbose)
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching text search 
configurations"));
+       addQueryComment(&buf, gettext_noop("Get matching text search 
configurations"));
        appendPQExpBuffer(&buf,
                                          "SELECT\n"
                                          "   n.nspname as \"%s\",\n"
@@ -5940,7 +5913,7 @@ listTSConfigsVerbose(const char *pattern)
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching text search 
configurations"));
+       addQueryComment(&buf, gettext_noop("Get matching text search 
configurations"));
        appendPQExpBufferStr(&buf,
                                                 "SELECT c.oid, c.cfgname,\n"
                                                 "   n.nspname,\n"
@@ -6027,7 +6000,7 @@ describeOneTSConfig(const char *oid, const char *nspname, 
const char *cfgname,
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get text search configuration 
details"));
+       addQueryComment(&buf, gettext_noop("Get text search configuration 
details"));
        appendPQExpBuffer(&buf,
                                          "SELECT\n"
                                          "  ( SELECT t.alias FROM\n"
@@ -6097,7 +6070,7 @@ listForeignDataWrappers(const char *pattern, bool verbose)
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching foreign-data 
wrappers"));
+       addQueryComment(&buf, gettext_noop("Get matching foreign-data 
wrappers"));
        appendPQExpBuffer(&buf,
                                          "SELECT fdw.fdwname AS \"%s\",\n"
                                          "  
pg_catalog.pg_get_userbyid(fdw.fdwowner) AS \"%s\",\n"
@@ -6170,7 +6143,7 @@ listForeignServers(const char *pattern, bool verbose)
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching foreign 
servers"));
+       addQueryComment(&buf, gettext_noop("Get matching foreign servers"));
        appendPQExpBuffer(&buf,
                                          "SELECT s.srvname AS \"%s\",\n"
                                          "  
pg_catalog.pg_get_userbyid(s.srvowner) AS \"%s\",\n"
@@ -6248,7 +6221,7 @@ listUserMappings(const char *pattern, bool verbose)
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching user mappings"));
+       addQueryComment(&buf, gettext_noop("Get matching user mappings"));
        appendPQExpBuffer(&buf,
                                          "SELECT um.srvname AS \"%s\",\n"
                                          "  um.usename AS \"%s\"",
@@ -6305,7 +6278,7 @@ listForeignTables(const char *pattern, bool verbose)
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching foreign tables"));
+       addQueryComment(&buf, gettext_noop("Get matching foreign tables"));
        appendPQExpBuffer(&buf,
                                          "SELECT n.nspname AS \"%s\",\n"
                                          "  c.relname AS \"%s\",\n"
@@ -6379,7 +6352,7 @@ listExtensions(const char *pattern)
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching installed 
extensions"));
+       addQueryComment(&buf, gettext_noop("Get matching installed 
extensions"));
        appendPQExpBuffer(&buf,
                                          "SELECT e.extname AS \"%s\", "
                                          "e.extversion AS \"%s\", 
ae.default_version AS \"%s\","
@@ -6435,7 +6408,7 @@ listExtensionContents(const char *pattern)
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching installed 
extensions"));
+       addQueryComment(&buf, gettext_noop("Get matching installed 
extensions"));
        appendPQExpBufferStr(&buf,
                                                 "SELECT e.extname, e.oid\n"
                                                 "FROM pg_catalog.pg_extension 
e\n");
@@ -6505,7 +6478,7 @@ listOneExtensionContents(const char *extname, const char 
*oid)
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get installed extension's 
contents"));
+       addQueryComment(&buf, gettext_noop("Get installed extension's 
contents"));
        appendPQExpBuffer(&buf,
                                          "SELECT 
pg_catalog.pg_describe_object(classid, objid, 0) AS \"%s\"\n"
                                          "FROM pg_catalog.pg_depend\n"
@@ -6614,7 +6587,7 @@ listPublications(const char *pattern)
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching publications"));
+       addQueryComment(&buf, gettext_noop("Get matching publications"));
        appendPQExpBuffer(&buf,
                                          "SELECT pubname AS \"%s\",\n"
                                          "  
pg_catalog.pg_get_userbyid(pubowner) AS \"%s\",\n"
@@ -6766,7 +6739,7 @@ describePublications(const char *pattern)
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get details about matching 
publications"));
+       addQueryComment(&buf, gettext_noop("Get details about matching 
publications"));
        appendPQExpBufferStr(&buf,
                                                 "SELECT oid, pubname,\n"
                                                 "  
pg_catalog.pg_get_userbyid(pubowner) AS owner,\n"
@@ -6903,8 +6876,7 @@ describePublications(const char *pattern)
                if (!puballtables)
                {
                        /* Get the tables for the specified publication */
-                       printfPQExpBuffer(&buf, "/* %s */\n",
-                                                         _("Get tables 
published by this publication"));
+                       addQueryComment(&buf, gettext_noop("Get tables 
published by this publication"));
                        appendPQExpBufferStr(&buf, "SELECT n.nspname, 
c.relname");
                        if (pset.sversion >= 150000)
                        {
@@ -6941,8 +6913,7 @@ describePublications(const char *pattern)
                        if (pset.sversion >= 150000)
                        {
                                /* Get the schemas for the specified 
publication */
-                               printfPQExpBuffer(&buf, "/* %s */\n",
-                                                                 _("Get 
schemas published by this publication"));
+                               addQueryComment(&buf, gettext_noop("Get schemas 
published by this publication"));
                                appendPQExpBuffer(&buf,
                                                                  "SELECT 
n.nspname\n"
                                                                  "FROM 
pg_catalog.pg_namespace n\n"
@@ -6959,8 +6930,7 @@ describePublications(const char *pattern)
                        if (pset.sversion >= 190000)
                        {
                                /* Get tables in the EXCEPT clause for this 
publication */
-                               printfPQExpBuffer(&buf, "/* %s */\n",
-                                                                 _("Get tables 
excluded by this publication"));
+                               addQueryComment(&buf, gettext_noop("Get tables 
excluded by this publication"));
                                appendPQExpBuffer(&buf,
                                                                  "SELECT 
n.nspname || '.' || c.relname\n"
                                                                  "FROM 
pg_catalog.pg_class c\n"
@@ -7021,7 +6991,7 @@ describeSubscriptions(const char *pattern, bool verbose)
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching subscriptions"));
+       addQueryComment(&buf, gettext_noop("Get matching subscriptions"));
        appendPQExpBuffer(&buf,
                                          "SELECT subname AS \"%s\"\n"
                                          ",  
pg_catalog.pg_get_userbyid(subowner) AS \"%s\"\n"
@@ -7191,7 +7161,7 @@ listOperatorClasses(const char *access_method_pattern,
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching operator 
classes"));
+       addQueryComment(&buf, gettext_noop("Get matching operator classes"));
        appendPQExpBuffer(&buf,
                                          "SELECT\n"
                                          "  am.amname AS \"%s\",\n"
@@ -7293,7 +7263,7 @@ listOperatorFamilies(const char *access_method_pattern,
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get matching operator 
families"));
+       addQueryComment(&buf, gettext_noop("Get matching operator families"));
        appendPQExpBuffer(&buf,
                                          "SELECT\n"
                                          "  am.amname AS \"%s\",\n"
@@ -7384,7 +7354,7 @@ listOpFamilyOperators(const char *access_method_pattern,
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get operators of matching 
operator families"));
+       addQueryComment(&buf, gettext_noop("Get operators of matching operator 
families"));
        appendPQExpBuffer(&buf,
                                          "SELECT\n"
                                          "  am.amname AS \"%s\",\n"
@@ -7491,8 +7461,7 @@ listOpFamilyFunctions(const char *access_method_pattern,
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n",
-                                         _("Get support functions of matching 
operator families"));
+       addQueryComment(&buf, gettext_noop("Get support functions of matching 
operator families"));
        appendPQExpBuffer(&buf,
                                          "SELECT\n"
                                          "  am.amname AS \"%s\",\n"
@@ -7579,7 +7548,7 @@ listLargeObjects(bool verbose)
 
        initPQExpBuffer(&buf);
 
-       printfPQExpBuffer(&buf, "/* %s */\n", _("Get large objects"));
+       addQueryComment(&buf, gettext_noop("Get large objects"));
        appendPQExpBuffer(&buf,
                                          "SELECT oid as \"%s\",\n"
                                          "  
pg_catalog.pg_get_userbyid(lomowner) as \"%s\",\n  ",
-- 
2.37.1 (Apple Git-137.1)

Attachment: v3-0001-psql-Fall-back-to-English-for-unsafe-hidden-query.patch
Description: Binary data

Reply via email to