selecting random row values in postgres - Mailing list pgsql-sql

From Sumeet
Subject selecting random row values in postgres
Date
Msg-id 7539aebb0702231129s48399f26r8881c6eff81b0708@mail.gmail.com
Whole thread Raw
Responses Re: selecting random row values in postgres
List pgsql-sql
Hi all,<br /><br />I'm trying to write  a query to select random values from a set of 'GROUP BY'<br />....see the
scenariobelow to understand the problem here (the actual problem cannot be discussed here so i'm taking an example
scenario)<br /><br />Assume there is a table<br /><br />id | name | year_of_birth<br /><br />query: I want  to select
foreach year_of_birth a random name.<br /><br />--> so i do a group by year_of_birth, now i have a set of names, is
there any function to select just one name from these set of names. <br />The current approach i'm using to solve this
problemis <br /><br />1) getting these names in a single string using a custom function 'group_concat'<br />2) Convert
thesingle string into an array <br />3) use postgresql random function to generate  a random number <br />4) us the
randomnumber to select a element from the array previously created.<br /><br clear="all" />The solution is there but
it'skinda hack, is there any other better way of solving this problem.<br /><br /><br />Thanks, <br />Sumeet  

pgsql-sql by date:

Previous
From: Stefan Becker
Date:
Subject: how do I to generate a sequence Range or Set of integer constants
Next
From: "A. Kretschmer"
Date:
Subject: Re: how do I to generate a sequence Range or Set of integer constants