Thread: psql \dC incorrectly shows casts "with inout" as "binary coercible"on 9.5.14 and 11beta3

psql \dC incorrectly shows casts "with inout" as "binary coercible"on 9.5.14 and 11beta3

From
"jean.pierre.pelletier0"
Date:






To reproduce, compare the output of \dC on two built-in casts
(json to jsonb) and (xml to text) where only the the first is really "with inout".

I've been using the folllowing query which (I believe) correctly shows
the (json to jsonb) cast as "with inout"

SELECT
   CONCAT('CREATE CAST (',
      C.castSource::regType, ' AS ',
      C.castTarget::regType,') ',
      CASE c.castMethod
         WHEN 'b' THEN 'WITHOUT FUNCTION'
         WHEN 'f' THEN 'WITH FUNCTION ' || C.castFunc::regProc || '('
|| pg_get_function_identity_arguments(C.castFunc) || ')'
         WHEN 'i' THEN 'WITH INOUT'
      END,
      CASE c.castContext
         WHEN 'a' THEN ' AS ASSIGNMENT '
         WHEN 'e' THEN ''
         WHEN 'i' THEN ' AS IMPLICIT'
      END)
FROM
   pg_cast C

   INNER JOIN pg_type TS
   ON C.castSource = TS.oid

   INNER JOIN pg_type TT
   ON C.castTarget = TT.oid
WHERE
   (C.castSource::regType::text, C.castTarget::regType::text) IN
(('json','jsonb'), ('xml','text'));


I've also noticed that pgAdmin III 1.22.2 has the same bug,
while pgAdmin 4 3.2 displays "with inout" casts properly.

Thanks,
Jean-Pierre Pelletier
"jean.pierre.pelletier0" <jean.pierre.pelletier0@gmail.com> writes:
> To reproduce, compare the output of \dC on two built-in casts(json to jsonb) and (xml to text) where only the the
firstis really "with inout". 

Hm, yeah, it just does

                      "       CASE WHEN castfunc = 0 THEN '(binary coercible)'\n"
                      "            ELSE p.proname\n"
                      "       END as \"%s\",\n"

without regard for the castmethod column (which it can't necessarily
assume is there, anyway).  It's hard to be sure after all these
years whether this was intentional or just an oversight, unless maybe
Heikki remembers ... but I tend to agree that "(with inout)" would be
more apropos than "(binary coercible)".

Not sure if this rises to the level of a back-patchable bug.
People might be surprised if we change that output in minor releases.
But we could still squeeze it into v11, I think.

            regards, tom lane


Btw, pg_dump is handling this right.

Jean-Pierre Pelletier

Le ven. 31 août 2018 10:33, Tom Lane <tgl@sss.pgh.pa.us> a écrit :
"jean.pierre.pelletier0" <jean.pierre.pelletier0@gmail.com> writes:
> To reproduce, compare the output of \dC on two built-in casts(json to jsonb) and (xml to text) where only the the first is really "with inout".

Hm, yeah, it just does

                      "       CASE WHEN castfunc = 0 THEN '(binary coercible)'\n"
                      "            ELSE p.proname\n"
                      "       END as \"%s\",\n"

without regard for the castmethod column (which it can't necessarily
assume is there, anyway).  It's hard to be sure after all these
years whether this was intentional or just an oversight, unless maybe
Heikki remembers ... but I tend to agree that "(with inout)" would be
more apropos than "(binary coercible)".

Not sure if this rises to the level of a back-patchable bug.
People might be surprised if we change that output in minor releases.
But we could still squeeze it into v11, I think.

                        regards, tom lane
I wrote:
> Not sure if this rises to the level of a back-patchable bug.
> People might be surprised if we change that output in minor releases.
> But we could still squeeze it into v11, I think.

I pushed a fix into HEAD & v11.

            regards, tom lane


Re: psql \dC incorrectly shows casts "with inout" as "binarycoercible" on 9.5.14 and 11beta3

From
Jean-Pierre Pelletier
Date:
Awesome, thanks! 

Le ven. 31 août 2018 16:46, Tom Lane <tgl@sss.pgh.pa.us> a écrit :
I wrote:
> Not sure if this rises to the level of a back-patchable bug.
> People might be surprised if we change that output in minor releases.
> But we could still squeeze it into v11, I think.

I pushed a fix into HEAD & v11.

                        regards, tom lane