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