Re: Using random() in update produces same random value for all

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Using random() in update produces same random value for all
Дата
Msg-id 9738.1516652155@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Re: Using random() in update produces same random value for all  (Jeff Janes <jeff.janes@gmail.com>)
Список pgsql-general
Jeff Janes <jeff.janes@gmail.com> writes:
> On Mon, Jan 22, 2018 at 9:16 AM, Tom Lane <tgl@sss.pgh.pa.us> wrote:
>> The point here is that that's an uncorrelated subselect --- ie, it
>> contains no outer references --- so it need not be, and is not,
>> re-evaluated at every outer row.

> That seems rather circular.  Why shouldn't a volatile be honored as
> volatile just because it is in an uncorrelated sub-select?

It is honored as volatile: it will be re-evaluated every time the
sub-select is re-evaluated.  It's just that there's no cause to
re-evaluate the sub-select.

I poked through the SQL standard to see if it spells out the semantics
of uncorrelated subqueries anywhere, and couldn't find anything relevant
at all.  But this is how Postgres has understood the behavior of
sub-selects for a very long time (~20 years).  I'm pretty certain
that there are people depending on it to behave this way.

            regards, tom lane


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

Предыдущее
От: Jeff Janes
Дата:
Сообщение: Re: Using random() in update produces same random value for all
Следующее
От: Alban Hertroys
Дата:
Сообщение: Hardware advice