| From: | Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us> | 
|---|---|
| To: | Oleksii Kliukin <alexk(at)hintbits(dot)com> | 
| Cc: | Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>, pgsql-general(at)postgresql(dot)org | 
| Subject: | Re: dubious optimization of the function in SELECT INTO target list | 
| Date: | 2015-10-06 21:31:36 | 
| Message-ID: | 7372.1444167096@sss.pgh.pa.us | 
| Views: | Whole Thread | Raw Message | Download mbox | Resend email | 
| Thread: | |
| Lists: | pgsql-general | 
Oleksii Kliukin <alexk(at)hintbits(dot)com> writes:
> This should work, but I'm interested in finding out why the original statement behaves the way Ive 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
| From | Date | Subject | |
|---|---|---|---|
| Next Message | Steve Pribyl | 2015-10-07 03:28:21 | backup.old | 
| Previous Message | Adrian Klaver | 2015-10-06 21:11:10 | Re: dubious optimization of the function in SELECT INTO target list |