Skip to content

Commit 115bf1e

Browse files
committed
Fix psql's \dC command to annotate I/O conversion casts as such.
A cast declared WITH INOUT was described as '(binary coercible)', which seems pretty inaccurate; let's print '(with inout)' instead. Per complaint from Jean-Pierre Pelletier. This definitely seems like a bug fix, but given that it's been wrong since 8.4 and nobody complained before, I'm hesitant to back-patch a behavior change into stable branches. It doesn't seem too late for v11 though. Discussion: https://postgr.es/m/5b887023.1c69fb81.ff96e.6a1d@mx.google.com
1 parent c186ba1 commit 115bf1e

File tree

1 file changed

+38
-18
lines changed

1 file changed

+38
-18
lines changed

src/bin/psql/describe.c

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
#include <ctype.h>
1616

1717
#include "catalog/pg_attribute_d.h"
18+
#include "catalog/pg_cast_d.h"
1819
#include "catalog/pg_class_d.h"
1920
#include "catalog/pg_default_acl_d.h"
2021
#include "fe_utils/string_utils.h"
@@ -3953,37 +3954,56 @@ listCasts(const char *pattern, bool verbose)
39533954

39543955
initPQExpBuffer(&buf);
39553956

3956-
/*
3957-
* We need a left join to pg_proc for binary casts; the others are just
3958-
* paranoia. Also note that we don't attempt to localize '(binary
3959-
* coercible)', because there's too much risk of gettext translating a
3960-
* function name that happens to match some string in the PO database.
3961-
*/
39623957
printfPQExpBuffer(&buf,
39633958
"SELECT pg_catalog.format_type(castsource, NULL) AS \"%s\",\n"
3964-
" pg_catalog.format_type(casttarget, NULL) AS \"%s\",\n"
3965-
" CASE WHEN castfunc = 0 THEN '(binary coercible)'\n"
3966-
" ELSE p.proname\n"
3967-
" END as \"%s\",\n"
3968-
" CASE WHEN c.castcontext = 'e' THEN '%s'\n"
3969-
" WHEN c.castcontext = 'a' THEN '%s'\n"
3970-
" ELSE '%s'\n"
3971-
" END as \"%s\"",
3959+
" pg_catalog.format_type(casttarget, NULL) AS \"%s\",\n",
39723960
gettext_noop("Source type"),
3973-
gettext_noop("Target type"),
3974-
gettext_noop("Function"),
3961+
gettext_noop("Target type"));
3962+
3963+
/*
3964+
* We don't attempt to localize '(binary coercible)' or '(with inout)',
3965+
* because there's too much risk of gettext translating a function name
3966+
* that happens to match some string in the PO database.
3967+
*/
3968+
if (pset.sversion >= 80400)
3969+
appendPQExpBuffer(&buf,
3970+
" CASE WHEN c.castmethod = '%c' THEN '(binary coercible)'\n"
3971+
" WHEN c.castmethod = '%c' THEN '(with inout)'\n"
3972+
" ELSE p.proname\n"
3973+
" END AS \"%s\",\n",
3974+
COERCION_METHOD_BINARY,
3975+
COERCION_METHOD_INOUT,
3976+
gettext_noop("Function"));
3977+
else
3978+
appendPQExpBuffer(&buf,
3979+
" CASE WHEN c.castfunc = 0 THEN '(binary coercible)'\n"
3980+
" ELSE p.proname\n"
3981+
" END AS \"%s\",\n",
3982+
gettext_noop("Function"));
3983+
3984+
appendPQExpBuffer(&buf,
3985+
" CASE WHEN c.castcontext = '%c' THEN '%s'\n"
3986+
" WHEN c.castcontext = '%c' THEN '%s'\n"
3987+
" ELSE '%s'\n"
3988+
" END AS \"%s\"",
3989+
COERCION_CODE_EXPLICIT,
39753990
gettext_noop("no"),
3991+
COERCION_CODE_ASSIGNMENT,
39763992
gettext_noop("in assignment"),
39773993
gettext_noop("yes"),
39783994
gettext_noop("Implicit?"));
39793995

39803996
if (verbose)
39813997
appendPQExpBuffer(&buf,
3982-
",\n d.description AS \"%s\"\n",
3998+
",\n d.description AS \"%s\"",
39833999
gettext_noop("Description"));
39844000

4001+
/*
4002+
* We need a left join to pg_proc for binary casts; the others are just
4003+
* paranoia.
4004+
*/
39854005
appendPQExpBufferStr(&buf,
3986-
"FROM pg_catalog.pg_cast c LEFT JOIN pg_catalog.pg_proc p\n"
4006+
"\nFROM pg_catalog.pg_cast c LEFT JOIN pg_catalog.pg_proc p\n"
39874007
" ON c.castfunc = p.oid\n"
39884008
" LEFT JOIN pg_catalog.pg_type ts\n"
39894009
" ON c.castsource = ts.oid\n"

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy