Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1ZpkRE-0004wB-17 for pgsql-bugs@arkaria.postgresql.org; Fri, 23 Oct 2015 22:03:52 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.84) (envelope-from ) id 1ZpkRD-0005Sj-JO for pgsql-bugs@arkaria.postgresql.org; Fri, 23 Oct 2015 22:03:51 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZpkRC-0005QZ-Mh for pgsql-bugs@postgresql.org; Fri, 23 Oct 2015 22:03:50 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84) (envelope-from ) id 1ZpkRA-00041o-BH for pgsql-bugs@postgresql.org; Fri, 23 Oct 2015 22:03:49 +0000 Received: from pro.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id t9NM3jOX015289; Fri, 23 Oct 2015 18:03:45 -0400 From: Tom Lane To: yozh.ne@gmail.com cc: pgsql-bugs@postgresql.org Subject: Re: BUG #13708: strange behaviour instead of syntax error In-reply-to: <20151023100339.931.54397@wrigleys.postgresql.org> References: <20151023100339.931.54397@wrigleys.postgresql.org> Comments: In-reply-to yozh.ne@gmail.com message dated "Fri, 23 Oct 2015 10:03:39 -0000" Date: Fri, 23 Oct 2015 15:03:45 -0700 Message-ID: <61779.1445637825@sss.pgh.pa.us> X-Pg-Spam-Score: -1.9 (-) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org 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