[HACKERS] Malformed Array Literal in PL/pgSQL Exception Block

Поиск
Список
Период
Сортировка
От David E. Wheeler
Тема [HACKERS] Malformed Array Literal in PL/pgSQL Exception Block
Дата
Msg-id F66306DC-B544-4177-9357-6B41017753E6@justatheory.com
обсуждение исходный текст
Ответы Re: [HACKERS] Malformed Array Literal in PL/pgSQL Exception Block
Re: [HACKERS] Malformed Array Literal in PL/pgSQL Exception Block
Список 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 по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: [HACKERS] recent deadlock regression test failures
Следующее
От: Michael Paquier
Дата:
Сообщение: Re: [HACKERS] SCRAM authentication, take three