Re: Selecting a random row - Mailing list pgsql-general

From Kari Lavikka
Subject Re: Selecting a random row
Date
Msg-id Pine.HPX.4.51.0411041950160.3138@purple.bdb.fi
Whole thread Raw
In response to Re: Selecting a random row  ("gnari" <gnari@simnet.is>)
List pgsql-general
> Tthe problem with this is that this is not very random.
> If the uids 30000 to 39999 have been missing, but
> the uids are more or less contiguous apart from that,
> the uid 40000 would be 10000 times more likely to be selected
> than average.

There are some gaps but distribution of them is quite uniform. And results
seem to be random enuff for this particular purpose.

> Maybe using an OFFSET of (count(*) * random()) and a LIMIT 1
> could be practical.

Something like OFFSET (random() * 10) could be used for additional
randomness of course.

    |\__/|
    ( oo )    Kari Lavikka - tuner@bdb.fi
__ooO(  )Ooo_______ _____ ___ _ _  _   _    _      _                  _
      ""


pgsql-general by date:

Previous
From: Tom Lane
Date:
Subject: Re: Selecting a random row
Next
From: Thomas F.O'Connell
Date:
Subject: Re: create a text file from postgres (like Oracle UTL_FILE package)