Re: [PERFORM] Getting a random row

2009-10-14 Thread Віталій Тимчишин
2009/10/14 Scott Marlowe > On Wed, Oct 14, 2009 at 1:20 AM, Pavel Stehule > wrote: > > 2009/10/14 Thom Brown : > >> 2009/10/14 Scott Marlowe : > >> Why not just do something like: > >> > >> SELECT thisfield, thatfield > >> FROM my_table > >> WHERE thisfield IS NOT NULL > >> ORDER BY RANDOM() > >

Re: [PERFORM] Getting a random row

2009-10-14 Thread Scott Marlowe
On Wed, Oct 14, 2009 at 1:20 AM, Pavel Stehule wrote: > 2009/10/14 Thom Brown : >> 2009/10/14 Scott Marlowe : >>> >>> If what you're trying to do is emulate a real world app which randomly >>> grabs rows, then you want to setup something ahead of time that has a >>> pseudo random order and not rel

Re: [PERFORM] Getting a random row

2009-10-14 Thread Pavel Stehule
2009/10/14 Thom Brown : > 2009/10/14 Scott Marlowe : >> >> If what you're trying to do is emulate a real world app which randomly >> grabs rows, then you want to setup something ahead of time that has a >> pseudo random order and not rely on using anything like order by >> random() limit 1 or anyth

Re: [PERFORM] Getting a random row

2009-10-13 Thread Thom Brown
2009/10/14 Scott Marlowe : > > If what you're trying to do is emulate a real world app which randomly > grabs rows, then you want to setup something ahead of time that has a > pseudo random order and not rely on using anything like order by > random() limit 1 or anything like that.  Easiest way is

Re: [PERFORM] Getting a random row

2009-10-13 Thread Scott Marlowe
On Tue, Oct 13, 2009 at 9:17 AM, Shaul Dar wrote: > Hi, > > I am running performance simulation against a DB. I want to randomly pull > different records from a large table. However the table has no columns that > hold sequential integer values (1..MAX), i.e. the columns all have "holes" > (due to

Re: [PERFORM] Getting a random row

2009-10-13 Thread bricklen
2009/10/13 Grzegorz Jaśkiewicz : > > > 2009/10/13 Shaul Dar >> >> Sorry, I guess I wasn't clear. >> I have an existing table in my DB, and it doesn't have a column with >> serial values (actually it did originally, but due to later deletions of >> about 2/3 of the rows the column now has "holes").

Re: [PERFORM] Getting a random row

2009-10-13 Thread Robert Haas
2009/10/13 Grzegorz Jaśkiewicz : > > > 2009/10/13 Shaul Dar >> >> Sorry, I guess I wasn't clear. >> I have an existing table in my DB, and it doesn't have a column with >> serial values (actually it did originally, but due to later deletions of >> about 2/3 of the rows the column now has "holes").

Re: [PERFORM] Getting a random row

2009-10-13 Thread Shaul Dar
Michael, You are right. I didn't remember the semantics, and Oracle's rownum would not have been helpful. But the new row_number() in 8.4 would probably do the trick (though I use 8.3.7 :-( ) -- Shaul 2009/10/13 Michael Glaesemann > > On Oct 13, 2009, at 11:19 , Grzegorz Jaśkiewicz wrote: > >

Re: [PERFORM] Getting a random row

2009-10-13 Thread Grzegorz Jaśkiewicz
2009/10/13 Shaul Dar > Sorry, I guess I wasn't clear. > I have an existing table in my DB, and it doesn't have a column with serial > values (actually it did originally, but due to later deletions of about 2/3 > of the rows the column now has "holes"). I realize I could add a new serial > column,

Re: [PERFORM] Getting a random row

2009-10-13 Thread Michael Glaesemann
On Oct 13, 2009, at 11:19 , Grzegorz Jaśkiewicz wrote: On Tue, Oct 13, 2009 at 4:17 PM, Shaul Dar wrote: Also PG does not have a concept of an auto-increment pseudo-column like Oracle's "rownum". Any suggestions? not true - it has sequences, and pseudo type serial. Rtfm!. AIUI, rownum

Re: [PERFORM] Getting a random row

2009-10-13 Thread Shaul Dar
Sorry, I guess I wasn't clear. I have an existing table in my DB, and it doesn't have a column with serial values (actually it did originally, but due to later deletions of about 2/3 of the rows the column now has "holes"). I realize I could add a new serial column, but prefer not to change table +

Re: [PERFORM] Getting a random row

2009-10-13 Thread Thomas Kellerer
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_nu

Re: [PERFORM] Getting a random row

2009-10-13 Thread Grzegorz Jaśkiewicz
On Tue, Oct 13, 2009 at 4:17 PM, Shaul Dar wrote: > Hi, > > I am running performance simulation against a DB. I want to randomly pull > different records from a large table. However the table has no columns that > hold sequential integer values (1..MAX), i.e. the columns all have "holes" > (due t

[PERFORM] Getting a random row

2009-10-13 Thread Shaul Dar
Hi, I am running performance simulation against a DB. I want to randomly pull different records from a large table. However the table has no columns that hold sequential integer values (1..MAX), i.e. the columns all have "holes" (due to earlier filtering). Also PG does not have a concept of an aut