Re: select random order by random - Mailing list pgsql-general

From Tom Lane
Subject Re: select random order by random
Date
Msg-id 9570.1193941378@sss.pgh.pa.us
Whole thread Raw
In response to Re: select random order by random  (Richard Huxton <dev@archonet.com>)
Responses Re: select random order by random  (Martijn van Oosterhout <kleptog@svana.org>)
List pgsql-general
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

pgsql-general by date:

Previous
From: Sam Mason
Date:
Subject: Re: select random order by random
Next
From: Tom Lane
Date:
Subject: Re: Solaris 10, mod_auth_pgsql2