Re: BUG #6067: In PL/pgsql, EXISTS(SELECT ... INTO...) fails

From: Pavel Stehule <pavel(dot)stehule(at)gmail(dot)com>
To: David Fetter <dfetter(at)vmware(dot)com>
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: BUG #6067: In PL/pgsql, EXISTS(SELECT ... INTO...) fails
Date: 2011-06-18 20:18:42
Message-ID: BANLkTi=tsNRPjNP+WbAeSLuJnO4KzP1PYQ@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

Hello

2011/6/18 David Fetter <dfetter(at)vmware(dot)com>:
>
> The following bug has been logged online:
>
> Bug reference:      6067
> Logged by:          David Fetter
> Email address:      dfetter(at)vmware(dot)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

You cannot to use PLpgSQL's addition "INTO" inside SQL statement. This
is not bug. INTO and STRICT are not SQL keywords, so they cannot be
used inside SQL expression.

Regards

Pavel Stehule

>                                            ^
>
> 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.
>
> --
> Sent via pgsql-bugs mailing list (pgsql-bugs(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-bugs
>

In response to

Browse pgsql-bugs by date

  From Date Subject
Next Message Tom Lane 2011-06-18 20:30:51 Re: BUG #6067: In PL/pgsql, EXISTS(SELECT ... INTO...) fails
Previous Message Greg Smith 2011-06-18 05:58:19 Re: could not read block XXXXX in file "base/YYYYY/ZZZZZZ": read only 160 of 8192 bytes