David Newall <davidn-postgres@rebel.net.au> writes:
> NOW CONSIDER the following query, executed using psql:
> SELECT i, j from (
> SELECT i, ((i + 18 * random())::integer % 20 + 1) AS j FROM data
> ) foo WHERE j = 15;
Hmph. Evidently the planner should refuse to flatten subselects that
have volatile functions in their output list (and perhaps anywhere
else??). This will probably make some people unhappy, but I see no
other fix.
I assume though that this is a made-up example and is not the case
that's really troubling you. What is the actual problem you are looking
at?
regards, tom lane