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

From: Chris Mair <chris(at)1006(dot)org>
To: Kiran <bangalore(dot)kiran(at)gmail(dot)com>, pgsql-general <pgsql-general(at)postgresql(dot)org>
Subject: Re: Best way to return Random rows from a table with non-repeatability of rows
Date: 2016-10-29 13:18:17
Message-ID: bc1cc5454658a4fff6f3779645098576@smtp.hushmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

> 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.

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Kim Rose Carlsen 2016-10-29 13:27:41 Re: How to hint 2 coulms IS NOT DISTINCT FROM each other
Previous Message Scott Marlowe 2016-10-29 13:02:11 Re: How to hint 2 coulms IS NOT DISTINCT FROM each other