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

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Jeff Janes <jeff(dot)janes(at)gmail(dot)com>
Cc: Olleg Samoylov <splarv(at)ya(dot)ru>, "pgsql-general(at)lists(dot)postgresql(dot)org" <pgsql-general(at)lists(dot)postgresql(dot)org>
Subject: Re: Using random() in update produces same random value for all
Date: 2018-01-22 20:15:55
Message-ID: 9738.1516652155@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Jeff Janes <jeff(dot)janes(at)gmail(dot)com> writes:
> On Mon, Jan 22, 2018 at 9:16 AM, Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Alban Hertroys 2018-01-22 20:46:56 Hardware advice
Previous Message Jeff Janes 2018-01-22 20:01:58 Re: Using random() in update produces same random value for all