From: Kristo Kaiv <kristo.kaiv@skype.net>
To: Stefan Zweig <stefanzweig1881@web.de>
Cc: pgsql-sql@postgresql.org
Subject: Re: strange result for select * from table where id=random()*900
Date: Fri, 27 Jul 2007 12:23:22 +0300
Message-ID: <B1941B8F-B359-4818-89FF-8966936E3FC0@skype.net> (raw)
In-Reply-To: <156384696@web.de>
References: <156384696@web.de>
On 27.07.2007, at 10:48, Stefan Zweig wrote:
> hi list,
>
> this is my query:
>
> select
> *
> from _g2977
> where
> id=floor(random() * (900));
>
> in table _g2977 i have id(s) from 1 up to 900. i just want to
> select one random dataset by the above query but i does not work.
>
> actually i get sometime zero, sometimes one, sometimes two and
> sometimes even three results back from the above query although i
> thought it should give only one random dataset from the table.
>
> what is wrong?
>
> i appreciate any help.
>
> thanks in advance, stefan
> ______________________________________________________________________
> ___
> In 5 Schritten zur eigenen Homepage. Jetzt Domain sichern und
> gestalten!
> Nur 3,99 EUR/Monat! http://www.maildomain.web.de/?mc=021114
>
>
> ---------------------------(end of
> broadcast)---------------------------
> TIP 5: don't forget to increase your free space map settings
SELECT * FROM _g2977 g,
(SELECT floor(random() * (900) as rnd) r
WHERE g.id = r.rnd
should work better, haven't tested though.
Kristo Kaiv
http://kaiv.wordpress.com (PostgreSQL blog)
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: kristo.kaiv@skype.net, stefanzweig1881@web.de
Subject: Re: strange result for select * from table where id=random()*900
In-Reply-To: <B1941B8F-B359-4818-89FF-8966936E3FC0@skype.net>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox