some random() clarification needed

Поиск
Список
Период
Сортировка
От Marc Millas
Тема some random() clarification needed
Дата
Msg-id CADX_1aa3BNFvW_ivrao1NJFWFdiYbhDxg9vUGUDZz-7YuRwvqQ@mail.gmail.com
обсуждение исходный текст
Ответы Re: some random() clarification needed  ("David G. Johnston" <david.g.johnston@gmail.com>)
Список pgsql-general
Hi,

when, in psql, on a postgres 12.3, I write:
select ceiling(random()*2582);
it does provide the expected answer, ie. a number between 1 and 2582, inclusive.
allways.
when I decide to use this to get a random row within a table prenoms having 2 columns
a id serial, and a prenom varchar, with explicitly 2582 lines, no gaps,
I write:
select id, prenom from prenoms where id=ceiling(random()*2582);

expecting to get, allways, one line.
But its not the case.
around 15% of time I get 0 lines which is already quite strange to me.
but 10% of time, I get a random number of lines, until now up to 4.
even weirder (to me !)

so, can someone please clarify ?

thanks,
regards,


Marc MILLAS
Senior Architect
+33607850334

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

Предыдущее
От: Toomas Kristin
Дата:
Сообщение: Re: Both side privileges
Следующее
От: "David G. Johnston"
Дата:
Сообщение: Re: some random() clarification needed