Re: Getting a random row

Поиск
Список
Период
Сортировка
От bricklen
Тема Re: Getting a random row
Дата
Msg-id 33b743250910131721l6a4f6de4i24395ff76c5c416e@mail.gmail.com
обсуждение исходный текст
Ответ на Re: Getting a random row  (Grzegorz Jaśkiewicz <gryzman@gmail.com>)
Список pgsql-performance
2009/10/13 Grzegorz Jaśkiewicz <gryzman@gmail.com>:
>
>
> 2009/10/13 Shaul Dar <shauldar@gmail.com>
>>
>> Sorry, I guess I wasn't clear.
>> I have an existing table in my DB, and it doesn't have a column with
>> serial values (actually it did originally, but due to later deletions of
>> about 2/3 of the rows the column now has "holes"). I realize I could add a
>> new serial column, but prefer not to change table + the new column would
>> also become nonconsecutive after further deletions. The nice thing about
>> Oracle's "rownum" is that it' a pseudo-column", not a real one, and AFAIK is
>> always valid.
>
> change the default of that column to use sequence.
> For instance, lookup CREATE SEQUENCE in manual, and ALTER TABLE .. SET
> DEFAULT ..
>
> for example of how it looks, just create table foo(a serial), and check its
> definition with \d+ foo
>
>
>
> --
> GJ
>


You could emulate rownum (aka rank) using a TEMPORARY sequence applied
to your result set.

http://www.postgresql.org/docs/8.3/interactive/sql-createsequence.html

Not sure if this is what you're after though?

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

Предыдущее
От: Robert Haas
Дата:
Сообщение: Re: Getting a random row
Следующее
От: Scott Marlowe
Дата:
Сообщение: Re: Getting a random row