Re: select random order by random

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: select random order by random
Дата
Msg-id 9570.1193941378@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: select random order by random  (Richard Huxton <dev@archonet.com>)
Ответы Re: select random order by random
Список 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 по дате отправления:

Предыдущее
От: Sam Mason
Дата:
Сообщение: Re: select random order by random
Следующее
От: Tom Lane
Дата:
Сообщение: Re: Solaris 10, mod_auth_pgsql2