Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ediVd-0005Bd-T8 for pgsql-general@arkaria.postgresql.org; Mon, 22 Jan 2018 20:16:01 +0000 Received: from localhost ([127.0.0.1] helo=malur.postgresql.org) by malur.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ediVd-0002yx-7i for pgsql-general@arkaria.postgresql.org; Mon, 22 Jan 2018 20:16:01 +0000 Received: from makus.postgresql.org ([2001:4800:1501:1::229]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ediVc-0002yN-Sz for pgsql-general@lists.postgresql.org; Mon, 22 Jan 2018 20:16:01 +0000 Received: from sss.pgh.pa.us ([66.207.139.130]) by makus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ediVa-0008V9-9M for pgsql-general@lists.postgresql.org; Mon, 22 Jan 2018 20:15:59 +0000 Received: from sss1.sss.pgh.pa.us (localhost [127.0.0.1]) by sss.pgh.pa.us (8.14.4/8.14.4) with ESMTP id w0MKFtXT009739; Mon, 22 Jan 2018 15:15:55 -0500 From: Tom Lane To: Jeff Janes cc: Olleg Samoylov , "pgsql-general@lists.postgresql.org" Subject: Re: Using random() in update produces same random value for all In-reply-to: References: <471561516635427@web43o.yandex.ru> <15531.1516641381@sss.pgh.pa.us> Comments: In-reply-to Jeff Janes message dated "Mon, 22 Jan 2018 12:01:58 -0800" MIME-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-ID: <9737.1516652155.1@sss.pgh.pa.us> Date: Mon, 22 Jan 2018 15:15:55 -0500 Message-ID: <9738.1516652155@sss.pgh.pa.us> List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Jeff Janes writes: > On Mon, Jan 22, 2018 at 9:16 AM, Tom Lane 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