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

From David E. Wheeler
Subject [HACKERS] Malformed Array Literal in PL/pgSQL Exception Block
Date
Msg-id F66306DC-B544-4177-9357-6B41017753E6@justatheory.com
Whole thread Raw
Responses Re: [HACKERS] Malformed Array Literal in PL/pgSQL Exception Block
Re: [HACKERS] Malformed Array Literal in PL/pgSQL Exception Block
List pgsql-hackers
Hackers,

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. When I run this:
   BEGIN;
   CREATE OR REPLACE FUNCTION foo(   ) RETURNS BOOLEAN IMMUTABLE LANGUAGE PLPGSQL AS $$   DECLARE       things TEXT[]
:='{}';   BEGIN       things := things || 'foo';       RAISE division_by_zero;   EXCEPTION WHEN OTHERS THEN
things:= things || 'bar';   END;   $$; 
   SELECT foo();
   ROLLBACK;

The output is:
   psql:array.sql:15: ERROR:  malformed array literal: "bar"   LINE 1: SELECT things || 'bar'
^   DETAIL:  Array value must start with "{" or dimension information.   QUERY:  SELECT things || 'bar'   CONTEXT:
PL/pgSQLfunction foo() line 8 at assignment 

Note that it’s fine with the use of || outside the exception block, but not inside! I’ve worked around this by using
`things|| '{bar}'` instead, but it seems like a bug or perhaps unforeseen corner case that appending a value to an
arraydoesn’t work in an exception-handling block. 

Best,

David


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: [HACKERS] recent deadlock regression test failures
Next
From: Michael Paquier
Date:
Subject: Re: [HACKERS] SCRAM authentication, take three