Re: [HACKERS] Malformed Array Literal in PL/pgSQL Exception Block - Mailing list pgsql-hackers

From Tom Lane
Subject Re: [HACKERS] Malformed Array Literal in PL/pgSQL Exception Block
Date
Msg-id 12765.1491799386@sss.pgh.pa.us
Whole thread Raw
In response to [HACKERS] Malformed Array Literal in PL/pgSQL Exception Block  ("David E. Wheeler" <david@justatheory.com>)
List pgsql-hackers
"David E. Wheeler" <david@justatheory.com> writes:
> I’ve been happily using the array-to-element concatenation operator || to append a single value to an array, e.g,
>     SELECT array || 'foo';
> And it works great, including in PL/pgSQL functions, except in an
> exception block.

Hm, really?

regression=# create table zit (things text[]);
CREATE TABLE
regression=# insert into zit values(array['foo','bar']);
INSERT 0 1
regression=# select things || 'baz' from zit;
ERROR:  malformed array literal: "baz"
LINE 1: select things || 'baz' from zit;                        ^
DETAIL:  Array value must start with "{" or dimension information.

I think the problem here is that without any other info about the
type of the right-hand argument of the || operator, the parser will
assume that it's the same type as the left-hand argument; which
is not unreasonable, because there is an array || array operator.

If you are more specific about the type of the RHS then it's fine:

regression=# select things || 'baz'::text from zit;  ?column?
---------------{foo,bar,baz}
(1 row)

> Note that it’s fine with the use of || outside the exception block, but
> not inside!

Don't see why an exception block would have anything to do with it.
        regards, tom lane



pgsql-hackers by date:

Previous
From: Michael Paquier
Date:
Subject: Re: [HACKERS] SCRAM authentication, take three
Next
From: Michael Paquier
Date:
Subject: Re: [HACKERS] [COMMITTERS] pgsql: Sync pg_dump and pg_dumpall output