Best way to return Random rows from a table with non-repeatability of rows

Started by Kiranover 9 years ago3 messagesgeneral
Jump to latest
#1Kiran
bangalore.kiran@gmail.com

Dear folks,

I have a table with thousands of rows ( currently 15 thousand but will grow
very fast).
I need to return from the query rows which are random and non-repeating.
I know there is random() function, but would like to know from postgresql
practitioners before embarking that path.
Please let me know what is best way to handle this type of queries.

regards
Kiran

#2Chris Mair
chris@1006.org
In reply to: Kiran (#1)
Re: Best way to return Random rows from a table with non-repeatability of rows

Dear folks,

I have a table with thousands of rows ( currently 15 thousand but will grow very fast).
I need to return from the query rows which are random and non-repeating.
I know there is random() function, but would like to know from postgresql practitioners before embarking that path.
Please let me know what is best way to handle this type of queries.

regards
Kiran

Hi,

if you're using Postgres >= 9.5 what you are looking for is TABLESAMPLE.

Syntax is here:
https://www.postgresql.org/docs/9.5/static/sql-select.html

Google tablesample+postgres to get some examples on how to use it.

Bye,
Chris.

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#3Kiran
bangalore.kiran@gmail.com
In reply to: Chris Mair (#2)
Re: Best way to return Random rows from a table with non-repeatability of rows

Hi Chris,

Thank you very much. Will look into examples and syntax.

regards
Kiran

On Sat, Oct 29, 2016 at 3:18 PM, Chris Mair <chris@1006.org> wrote:

Show quoted text

Dear folks,

I have a table with thousands of rows ( currently 15 thousand but will
grow very fast).
I need to return from the query rows which are random and non-repeating.
I know there is random() function, but would like to know from
postgresql practitioners before embarking that path.
Please let me know what is best way to handle this type of queries.

regards
Kiran

Hi,

if you're using Postgres >= 9.5 what you are looking for is TABLESAMPLE.

Syntax is here:
https://www.postgresql.org/docs/9.5/static/sql-select.html

Google tablesample+postgres to get some examples on how to use it.

Bye,
Chris.