Re: ORDER BY random() LIMIT 1 slowness

Поиск
Список
Период
Сортировка
От SZUCS Gábor
Тема Re: ORDER BY random() LIMIT 1 slowness
Дата
Msg-id 007201c2a688$0725dc40$0a03a8c0@fejleszt2
обсуждение исходный текст
Ответ на ORDER BY random() LIMIT 1 slowness  ("Gavin M. Roy" <gmr@justsportsusa.com>)
Ответы Re: ORDER BY random() LIMIT 1 slowness  (Tom Lane <tgl@sss.pgh.pa.us>)
Список pgsql-general
----- Original Message -----
From: "Jean-Luc Lachance" <jllachan@nsd.ca>
Sent: Tuesday, December 17, 2002 5:04 PM


> Gavin,
>
> Assuming that you have a serial column rand on poetry and you did not
> delete any row,
> here is my suggestion:
>
> CREATE TABLE poetry ( rand SERIAL, ... );
>
> SELECT * FROM poetry WHERE rand = (
>   SELECT int8( curval( 'poetry_rand_seq') * random()));


Mmmm... It usually doesn't work for me. Isn't currval (NOTE: with two r's)
bound to session and has no meaning before the first call to nextval()?
7.2.1 says the following; has it changed in 7.3(.*)?

---------------------------- cut here ------------------------------
tir=> create sequence test_seq;
CREATE
tir=> select currval('test_seq');
ERROR:  test_seq.currval is not yet defined in this session
tir=> select nextval('test_seq');
 nextval
---------
       1
(1 row)

tir=> select currval('test_seq');
 currval
---------
       1
(1 row)
---------------------------- cut here ------------------------------

G.
--
while (!asleep()) sheep++;

---------------------------- cut here ------------------------------


В списке pgsql-general по дате отправления:

Предыдущее
От: Ken Guest
Дата:
Сообщение: converting string value to integer
Следующее
От: Conxita Marín
Дата:
Сообщение: SELECT EXTRACT doesn't work with variables?