From: Tom Lane <tgl@sss.pgh.pa.us>
To: yozh.ne@gmail.com
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #13708: strange behaviour instead of syntax error
Date: Fri, 23 Oct 2015 15:03:45 -0700
Message-ID: <61779.1445637825@sss.pgh.pa.us> (raw)
In-Reply-To: <20151023100339.931.54397@wrigleys.postgresql.org>
References: <20151023100339.931.54397@wrigleys.postgresql.org>
List-Unsubscribe: <mailto:majordomo@postgresql.org?body=unsub%20pgsql-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
--
Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-bugs
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, yozh.ne@gmail.com
Subject: Re: BUG #13708: strange behaviour instead of syntax error
In-Reply-To: <61779.1445637825@sss.pgh.pa.us>
References: <20151023100339.931.54397@wrigleys.postgresql.org> <61779.1445637825@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox