Re: select random order by random

From: Richard Huxton <dev(at)archonet(dot)com>
To: Gregory Stark <stark(at)enterprisedb(dot)com>
Cc: Scott Marlowe <scott(dot)marlowe(at)gmail(dot)com>, Lee Keel <lee(dot)keel(at)uai(dot)com>, piotr_sobolewski <piotr_sobolewski(at)o2(dot)pl>, pgsql-general(at)postgresql(dot)org
Subject: Re: select random order by random
Date: 2007-11-01 16:49:16
Message-ID: 472A038C.9020300@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Gregory Stark wrote:
> "Scott Marlowe" <scott(dot)marlowe(at)gmail(dot)com> writes:
>
>> I think that Piotr expected the random() to be evaluated in both
>> places separately.
>>
>> My guess is that it was recognized by the planner as the same function
>> and evaluated once per row only.
>>
>> If you try this:
>>
>> select random() from generate_series(1, 10) order by random()*1;
>>
>> then you'll get random ordering.
>
> 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;

--
Richard Huxton
Archonet Ltd

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Greg Quinn 2007-11-01 17:23:22 test
Previous Message Gregory Stark 2007-11-01 16:41:13 Re: select random order by random