Richard Huxton <dev@archonet.com> writes:
> Gregory Stark wrote:
>> This does strike me as wrong. random() is marked volatile and the planner
>> ought not collapse multiple calls into one.
> I think I agree with the earlier poster. Surely these two queries should
> be equivalent?
> SELECT random() FROM generate_series(1, 10) ORDER BY random();
> SELECT random() AS foo FROM generate_series(1, 10) ORDER BY foo;
Well, the latter case is why it acts that way, but Greg has a point that
when a volatile function is involved maybe they shouldn't be the same.
OTOH it's always been like that, and in the absence of a clear reason
to change it I'm inclined to leave it alone.
(BTW, this is not the planner's fault; the collapsing of the two
targetlist entries into one happens in the parser.)
regards, tom lane