From: Tom Lane <tgl@sss.pgh.pa.us>
To: Jeff Janes <jeff.janes@gmail.com>
Cc: Olleg Samoylov <splarv@ya.ru>
Cc: pgsql-general@lists.postgresql.org <pgsql-general@lists.postgresql.org>
Subject: Re: Using random() in update produces same random value for all
Date: Mon, 22 Jan 2018 15:15:55 -0500
Message-ID: <9738.1516652155@sss.pgh.pa.us> (raw)
In-Reply-To: <CAMkU=1xi9aRSMfB4Lz2C5yJfekqM4==0JuBTH9LqYcJzXA2-5Q@mail.gmail.com>
References: <CA+cR4zde6SSaMfznJRgrM1zB2NYHjh6Uzn1ARXYW9_4sRvvUPA@mail.gmail.com>
<CAD3a31Wkji3HCPxcRDdA6P6xHjjURV-YP_Z6wYitqSpc2G0e4g@mail.gmail.com>
<471561516635427@web43o.yandex.ru>
<15531.1516641381@sss.pgh.pa.us>
<CAMkU=1xi9aRSMfB4Lz2C5yJfekqM4==0JuBTH9LqYcJzXA2-5Q@mail.gmail.com>
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
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 from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-general@postgresql.org
Cc: tgl@sss.pgh.pa.us, jeff.janes@gmail.com, splarv@ya.ru
Subject: Re: Using random() in update produces same random value for all
In-Reply-To: <9738.1516652155@sss.pgh.pa.us>
References: <CA+cR4zde6SSaMfznJRgrM1zB2NYHjh6Uzn1ARXYW9_4sRvvUPA@mail.gmail.com> <CAD3a31Wkji3HCPxcRDdA6P6xHjjURV-YP_Z6wYitqSpc2G0e4g@mail.gmail.com> <471561516635427@web43o.yandex.ru> <15531.1516641381@sss.pgh.pa.us> <CAMkU=1xi9aRSMfB4Lz2C5yJfekqM4==0JuBTH9LqYcJzXA2-5Q@mail.gmail.com> <9738.1516652155@sss.pgh.pa.us>
* 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