Re: A question about PL/pgSQL DECLAREd variable behavior - Mailing list pgsql-general

From Dane Foster
Subject Re: A question about PL/pgSQL DECLAREd variable behavior
Date
Msg-id CA+WxinL8V4U3obYpa+wSrTXXLZswMKr=z5rH4sAEMYVrFO722Q@mail.gmail.com
Whole thread Raw
In response to Re: A question about PL/pgSQL DECLAREd variable behavior  (Thomas Munro <thomas.munro@enterprisedb.com>)
Responses Re: A question about PL/pgSQL DECLAREd variable behavior  (Jim Nasby <Jim.Nasby@BlueTreble.com>)
List pgsql-general
On Wed, Oct 21, 2015 at 10:23 PM, Thomas Munro <thomas.munro@enterprisedb.com> wrote:
On Thu, Oct 22, 2015 at 2:48 PM, Dane Foster <studdugie@gmail.com> wrote:
> I wrote the following simple function to try to learn what happens to a
> DECLAREd variable whose assignment comes from an INTO statement where the
> query being executed does not return a result.
>
> CREATE OR REPLACE FUNCTION _test() RETURNS BOOLEAN AS $$
> DECLARE r RECORD;
> BEGIN SELECT 1 AS one INTO r WHERE false; RETURN r IS NULL; END;
> $$ LANGUAGE plpgsql;
>
> The function returns true. Given that I can't find any explicit reference in
> the documentation about the behavior I've just described is it safe to
> assume that the current behavior is the expected behavior but it's just not
> documented?

http://www.postgresql.org/docs/9.4/static/plpgsql-statements.html#PLPGSQL-STATEMENTS-SQL-ONEROW

"If STRICT is not specified in the INTO clause, then target will be
set to the first row returned by the query, or to nulls if the query
returned no rows."

--
Thomas Munro
http://www.enterprisedb.com

​Foot removed from mouth.

Dane​

pgsql-general by date:

Previous
From: Thomas Munro
Date:
Subject: Re: A question about PL/pgSQL DECLAREd variable behavior
Next
From: Andreas Kretschmer
Date:
Subject: Re: temporary indexes?