Re: Getting a random row

From: Thomas Kellerer <spam_eater(at)gmx(dot)net>
To: pgsql-performance(at)postgresql(dot)org
Subject: Re: Getting a random row
Date: 2009-10-13 15:29:40
Message-ID: hb26d4$3kn$1@ger.gmane.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-performance

Shaul Dar, 13.10.2009 17:17:
> Also PG does not have a concept of an auto-increment pseudo-column
> like Oracle's "rownum". Any suggestions?

Yes it does (at least 8.4)

SELECT row_number() over(), the_other_columns...
FROM your_table

So you could do something like:

SELECT *
FROM (
SELECT row_number() over() as rownum,
the_other_columns...
FROM your_table
) t
WHERE t.rownum = a_random_integer_value_lower_than_rowcount;

Thomas

In response to

Browse pgsql-performance by date

  From Date Subject
Next Message Shaul Dar 2009-10-13 15:30:52 Re: Getting a random row
Previous Message Grzegorz Jaśkiewicz 2009-10-13 15:19:40 Re: Getting a random row