Re: select where id=random()*something returns two results

From: Ulrich Meis <u(dot)meis(at)gmx(dot)de>
To:
Cc: pgsql-bugs(at)postgresql(dot)org
Subject: Re: select where id=random()*something returns two results
Date: 2003-09-21 12:21:20
Message-ID: 000101c3803a$e05bffd0$9e318286@DAYWALK
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-bugs

> -----Original Message-----
> From: pgsql-bugs-owner(at)postgresql(dot)org [mailto:pgsql-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)));
>

How about

select * from quotes where id=1+int8((select random())*(select max(id)
from quotes));

It works, but is it more or less efficient?

In response to

Responses

Browse pgsql-bugs by date

  From Date Subject
Next Message Marko Karppinen 2003-09-21 19:06:24 Re: Can't Build 7.3.4 on OS X
Previous Message Ulrich Meis 2003-09-21 12:17:34 Re: select where id=random()*something returns two results