![]() | |
![]() |
| | Thread Tools | Display Modes |
#1
| |||
| |||
|
|
select * from quotes where id=1+round(random()* cast ((select max(id) from quotes) as double precision)); id | quote | author -----+-----------------------------------------------------------+------ ----------- 187 | Vergib Deinen Feinden, aber vergiss niemals ihre Namen. | John F. Kennedy 377 | Die Wirklichkeit ist nicht so oder so, sondern so und so. | Harry Mulisch (2 rows) I'm not really into databases, but this sounds wrong. Most of the time, I actually get 0 results. |
#2
| |||
| |||
|
|
select * from quotes where id=3D1+round(random()* cast ((select max(id) from quotes) as double precision)); id | quote | author=20=20=20=20=20=20 -----+-----------------------------------------------------------+------ ----------- 187 | Vergib Deinen Feinden, aber vergiss niemals ihre Namen. | John F. Kennedy 377 | Die Wirklichkeit ist nicht so oder so, sondern so und so. | Harry Mulisch (2 rows) =20 I'm not really into databases, but this sounds wrong. Most of the time, I actually get 0 results. |
#3
| |||
| |||
|
#4
| |||
| |||
|
Sorry for buggering you, I get the point ![]() |
#5
| |||
| |||
|
|
-----Original Message----- From: pgsql-bugs-owner (AT) postgresql (DOT) org [mailto gsql-bugs-owner (AT) postgresql (DOT) org] On Behalf Of Ian Grant Sent: Friday, September 19, 2003 1:02 PM To: Ulrich Meis Cc: Ian.Grant (AT) cl (DOT) cam.ac.uk; pgsql-bugs (AT) postgresql (DOT) org Subject: Re: [BUGS] select where id=random()*something returns two results Sorry for buggering you, I get the point ![]() I think you mean 'bugging.' Buggering is something quite different. |
#6
| |||
| |||
|
|
-----Original Message----- From: pgsql-bugs-owner (AT) postgresql (DOT) org [mailto gsql-bugs-owner (AT) postgresql (DOT) org] On Behalf Of Jean-Luc Lachance Sent: Friday, September 19, 2003 4:44 PM To: Rod Taylor Cc: Ulrich Meis; pgsql-bugs (AT) postgresql (DOT) org Subject: Re: [BUGS] select where id=random()*something returns two results Rod, If the table has 100,000 tupples your query is generating 100,000 new tupples... Try: select * from quotes where id = ( select int8( 1 + random() * ( select id from quotes order by id desc limit 1))); |
#7
| |||
| |||
|
|
-----Original Message----- From: pgsql-bugs-owner (AT) postgresql (DOT) org [mailto gsql-bugs-owner (AT) postgresql (DOT) org] On Behalf Of Jean-Luc Lachance Sent: Friday, September 19, 2003 4:44 PM To: Rod Taylor Cc: Ulrich Meis; pgsql-bugs (AT) postgresql (DOT) org Subject: Re: [BUGS] select where id=3Drandom()*something returns two results =20 Rod, =20 If the table has 100,000 tupples your query is generating 100,000 new tupples... Try: =20 select * from quotes where id =3D ( select int8( 1 + random() * ( select id from quotes order by id desc limit 1))); =20 =20 How about =20 select * from quotes where id=3D1+int8((select random())*(select max(id) from quotes)); =20 It works, but is it more or less efficient? |
![]() |
| Thread Tools | |
| Display Modes | |
| |