Re: BUG #13708: strange behaviour instead of syntax error

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: BUG #13708: strange behaviour instead of syntax error
Дата
Msg-id 61779.1445637825@sss.pgh.pa.us
обсуждение исходный текст
Ответ на BUG #13708: strange behaviour instead of syntax error  (yozh.ne@gmail.com)
Ответы Re: BUG #13708: strange behaviour instead of syntax error  (Greg Stark <stark@mit.edu>)
Список pgsql-bugs
yozh.ne@gmail.com writes:
> In the code below - if I remove semicolon after "po_result := 'ERROR: No
> uncollected prize found!'" then no syntax error occurs, return statement is
> just ignored instead

> IF NOT FOUND THEN
>     po_result := 'ERROR: No uncollected prize found!'
>     RETURN;
> END IF;

Hm, yeah.  The problem is that plpgsql doesn't have any native
intelligence about what expressions can contain.  It just takes
everything between ":=" and ";" and hands that to the main parser
with a SELECT in front, ie what you have here is

    SELECT 'ERROR: No uncollected prize found!' RETURN;

which is legal syntax -- the RETURN is an AS-less column label.

I'm not sure about a reasonably low-effort way to fix this (and,
given the lack of previous complaints, I doubt it's worth a lot
of work).  I experimented with forcibly adding an AS clause,
so that what would get parsed is

    SELECT 'ERROR: No uncollected prize found!' RETURN AS collabel;

but the error message that the main parser would produce is along the
line of "ERROR: syntax error at or near "AS"", which would be quite
opaque from the user's viewpoint since there is no AS in the text.

Hmmm ... maybe just adding parens would do the trick.

regression=# SELECT ('ERROR: No uncollected prize found!' RETURN);
ERROR:  syntax error at or near "RETURN"

That looks more promising ... though I'm not sure if there are
any cases it would break.

            regards, tom lane

В списке pgsql-bugs по дате отправления:

Предыдущее
От: yozh.ne@gmail.com
Дата:
Сообщение: BUG #13708: strange behaviour instead of syntax error
Следующее
От: Michael Paquier
Дата:
Сообщение: Re: BUG #13657: Some kind of undetected deadlock between query and "startup process" on replica.