Re: Bug? Me or PostgreSQL.

Поиск
Список
Период
Сортировка
От Tod McQuillin
Тема Re: Bug? Me or PostgreSQL.
Дата
Msg-id Pine.GSO.4.31.0102182344180.13057-100000@sysadmin
обсуждение исходный текст
Ответ на Bug? Me or PostgreSQL.  (Christopher Sawtell <csawtell@xtra.co.nz>)
Список pgsql-sql
On Mon, 19 Feb 2001, Christopher Sawtell wrote:

> How can this happen?
>
> chris=# select name from boys_names where
> boys_names.number=(random()*225+1)::int4;
>   name
> --------
>  Fred
>  Gunnar
>  Manuel
>  Rainer
> (4 rows)

It's not clear what you expected to see -- I'll guess you expected only
one row returned.

But random() is being called once for every row in the table -- it's not
surprising (if you have a lot of rows) that it comes up with a match more
than once.  Sometimes it might even return no rows at all.

SQL is not the best language for picking random members of a set.  You're
better off picking a random number in a procedural language and passing
that number as a constant to an embedded SQL query.
-- 
Tod McQuillin




В списке pgsql-sql по дате отправления:

Предыдущее
От: Tom Lane
Дата:
Сообщение: Re: Bug? Me or PostgreSQL.
Следующее
От: Ines.Klimann@liafa.jussieu.fr
Дата:
Сообщение: How to insert values with a new type ?