Re: dubious optimization of the function in SELECT INTO target list - Mailing list pgsql-general

From Tom Lane
Subject Re: dubious optimization of the function in SELECT INTO target list
Date
Msg-id 7372.1444167096@sss.pgh.pa.us
Whole thread Raw
In response to Re: dubious optimization of the function in SELECT INTO target list  (Oleksii Kliukin <alexk@hintbits.com>)
Responses Re: dubious optimization of the function in SELECT INTO target list
List pgsql-general
Oleksii Kliukin <alexk@hintbits.com> writes:
> This should work, but I'm interested in finding out why the original statement behaves the way I�ve described.

plpgsql's SELECT INTO is only capable of storing a single result row,
so it only executes the statement far enough to obtain one row, and
then stops (as though a LIMIT were present).  There is no guarantee
about how much useless computation will get done underneath.

If this is not the behavior you want, you shouldn't be using SELECT INTO
(which, I'll note, is very clearly documented as meant only for single-row
results).  A plausible alternative is a FOR IN SELECT loop, which would
have the benefit that you could actually do something with the row values.

            regards, tom lane


pgsql-general by date:

Previous
From: Adrian Klaver
Date:
Subject: Re: dubious optimization of the function in SELECT INTO target list
Next
From: Steve Pribyl
Date:
Subject: backup.old