Received: from maia.hub.org (maia-3.hub.org [200.46.204.243]) by mail.postgresql.org (Postfix) with ESMTP id 8C6A1B5DC73 for ; Fri, 17 Jun 2011 19:46:22 -0300 (ADT) Received: from mail.postgresql.org ([200.46.204.86]) by maia.hub.org (mx1.hub.org [200.46.204.243]) (amavisd-maia, port 10024) with ESMTP id 67378-01 for ; Fri, 17 Jun 2011 22:46:22 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from wwwmaster.postgresql.org (wwwmaster.postgresql.org [217.196.146.204]) by mail.postgresql.org (Postfix) with ESMTP id 618FFB5DC5C for ; Fri, 17 Jun 2011 19:46:03 -0300 (ADT) Received: from wwwmaster.postgresql.org (wwwmaster.postgresql.org [217.196.146.204]) by wwwmaster.postgresql.org (8.14.3/8.14.3) with ESMTP id p5HMk2VV041852 for ; Fri, 17 Jun 2011 22:46:02 GMT (envelope-from www@wwwmaster.postgresql.org) Received: (from www@localhost) by wwwmaster.postgresql.org (8.14.3/8.14.3/Submit) id p5HMk2Qs041851; Fri, 17 Jun 2011 22:46:02 GMT (envelope-from www) Date: Fri, 17 Jun 2011 22:46:02 GMT Message-Id: <201106172246.p5HMk2Qs041851@wwwmaster.postgresql.org> To: pgsql-bugs@postgresql.org Subject: BUG #6067: In PL/pgsql, EXISTS(SELECT ... INTO...) fails From: "David Fetter" Content-Type: text/plain; charset=utf-8 X-Virus-Scanned: Maia Mailguard 1.0.1 X-Archive-Number: 201106/162 X-Sequence-Number: 30541 The following bug has been logged online: Bug reference: 6067 Logged by: David Fetter Email address: dfetter@vmware.com PostgreSQL version: 9.0.4 Operating system: Linux Description: In PL/pgsql, EXISTS(SELECT ... INTO...) fails Details: Here's some example code that reproduces the problem: CREATE OR REPLACE FUNCTION foo() RETURNS void LANGUAGE plpgsql AS $$ DECLARE i int; BEGIN IF EXISTS (SELECT 1 INTO STRICT i) THEN RAISE NOTICE '%', a; END IF; RETURN; END; $$; ERROR: syntax error at or near "i" LINE 8: IF EXISTS (SELECT 1 INTO STRICT i) THEN ^ This came up in a case where there was an IF block that checked some conditions before checking whether there was a row. If it found a row, it was supposed to use it in an EXCEPTION. Instead, I had to do the query unconditionally, check the FOUND block in a separate nested IF statement, and generally uglify the code. Not everybody in IRC agreed that this is a bug, though.