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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: yozh(dot)ne(at)gmail(dot)com
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #13708: strange behaviour instead of syntax error
Date: 2015-10-23 22:03:45
Message-ID: 61779.1445637825@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

yozh(dot)ne(at)gmail(dot)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

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Gowreswaran Sakthivel 2015-10-23 23:15:58 Reg Loging error mesages on ouput of sql script
Previous Message cstdenis 2015-10-23 20:35:03 BUG #13711: Error creating index on ltree column