Stephan Szabo <sszabo(at)megazone23(dot)bigpanda(dot)com> writes:
> However, I'd think:
> "select (select nextval from test_seq) from multiple_rows;"
> should give you different values and doesn't, although
> "select (select nextval from test_seq where i IS NULL or i IS NOT NULL)
> from multiple_rows;" does give you different values.
In the first case, the subselect is visibly not dependent on the outer
query, so it's evaluated only once; in the second case it has to be
re-evaluated for each row using that row's value of i. You can see the
difference (InitPlan vs. SubPlan) in the query's EXPLAIN output.
regards, tom lane