Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.84_2) (envelope-from ) id 1ede9u-0008Ds-JM for pgsql-general@arkaria.postgresql.org; Mon, 22 Jan 2018 15:37:19 +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 1ede9t-0000wY-RU for pgsql-general@arkaria.postgresql.org; Mon, 22 Jan 2018 15:37:17 +0000 Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.84_2) (envelope-from ) id 1ede9t-0000wP-Hq for pgsql-general@lists.postgresql.org; Mon, 22 Jan 2018 15:37:17 +0000 Received: from forward5j.cmail.yandex.net ([2a02:6b8:0:1630::18]) by magus.postgresql.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_CBC_SHA384:256) (Exim 4.89) (envelope-from ) id 1ede9m-0005X9-D7 for pgsql-general@lists.postgresql.org; Mon, 22 Jan 2018 15:37:17 +0000 Received: from mxback6j.mail.yandex.net (mxback6j.mail.yandex.net [IPv6:2a02:6b8:0:1619::10f]) by forward5j.cmail.yandex.net (Yandex) with ESMTP id 0044F20C3D for ; Mon, 22 Jan 2018 18:37:08 +0300 (MSK) Received: from web43o.yandex.ru (web43o.yandex.ru [2a02:6b8:0:1a2d::5:223]) by mxback6j.mail.yandex.net (nwsmtp/Yandex) with ESMTP id v1wYAiDujD-b7fSGLZ0; Mon, 22 Jan 2018 18:37:07 +0300 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ya.ru; s=mail; t=1516635427; bh=HI077WsUnqVHZnbXChoaLZudppQZACncT0z4gQGM79c=; h=From:To:References:Subject:Message-Id:Date; b=MxtXNC90KvHvtacmSf8MhdPtTJyrxdXT7ZuIWLR8WXeL2fupBdrVoKNQmT6qrbhYi k6MTiGdJLNujJcAuajnkjUorC6ISKzqBgBDxv2QskfWpY4kxCZs8uMi+XPl8GSVOGh SuOyMw/11VJgNwaaueCtuUi82W4zCPfH+aXPRV/Q= Authentication-Results: mxback6j.mail.yandex.net; dkim=pass header.i=@ya.ru Received: by web43o.yandex.ru with HTTP; Mon, 22 Jan 2018 18:37:07 +0300 From: Olleg Samoylov Envelope-From: splarv@yandex.ru To: "pgsql-general@lists.postgresql.org" References: Subject: Re: Using random() in update produces same random value for all MIME-Version: 1.0 Message-Id: <471561516635427@web43o.yandex.ru> X-Mailer: Yamail [ http://yandex.ru ] 5.0 Date: Mon, 22 Jan 2018 18:37:07 +0300 Content-Transfer-Encoding: 8bit Content-Type: text/plain; charset=utf-8 List-Id: List-Help: List-Subscribe: List-Post: List-Owner: List-Archive: Precedence: bulk Yep, interesting.  Checked with PostgreSQL 10.1. => select *,random() from generate_series(1,10);  generate_series |      random -----------------+-------------------                1 | 0.308531506918371                2 | 0.126279713585973                3 | 0.984668150078505                4 | 0.884970095474273                5 | 0.692738385871053                6 | 0.290897831786424                7 | 0.914066118188202                8 | 0.031909613404423                9 | 0.574441066011786               10 | 0.631192437838763 (10 rows) => select *,(select * from random()) from generate_series(1,10);  generate_series |       random -----------------+--------------------                1 | 0.0718352268449962                2 | 0.0718352268449962                3 | 0.0718352268449962                4 | 0.0718352268449962                5 | 0.0718352268449962                6 | 0.0718352268449962                7 | 0.0718352268449962                8 | 0.0718352268449962                9 | 0.0718352268449962               10 | 0.0718352268449962 (10 rows) => select *,(select random()) from generate_series(1,10);  generate_series |      random -----------------+-------------------                1 | 0.848611807450652                2 | 0.848611807450652                3 | 0.848611807450652                4 | 0.848611807450652                5 | 0.848611807450652                6 | 0.848611807450652                7 | 0.848611807450652                8 | 0.848611807450652                9 | 0.848611807450652               10 | 0.848611807450652 (10 rows) Looked like random() is "volatile", but in subselect it works like "stable".