pg.ddx.io  pgsql-general@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Olleg Samoylov <splarv@ya.ru>
To: 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 18:37:07 +0300
Message-ID: <471561516635427@web43o.yandex.ru> (raw)
References: <CA+cR4zde6SSaMfznJRgrM1zB2NYHjh6Uzn1ARXYW9_4sRvvUPA@mail.gmail.com>
	<CAD3a31Wkji3HCPxcRDdA6P6xHjjURV-YP_Z6wYitqSpc2G0e4g@mail.gmail.com>

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".




view thread (7+ messages)  latest in thread

Message-ID: <471561516635427@web43o.yandex.ru>
Permalink:  ../471561516635427@web43o.yandex.ru/
Also on:    postgresql.org/message-id/471561516635427@web43o.yandex.ru

 · 

reply

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: splarv@ya.ru
  Subject: Re: Using random() in update produces same random value for all
  In-Reply-To: <471561516635427@web43o.yandex.ru>
  References: <CA+cR4zde6SSaMfznJRgrM1zB2NYHjh6Uzn1ARXYW9_4sRvvUPA@mail.gmail.com> <CAD3a31Wkji3HCPxcRDdA6P6xHjjURV-YP_Z6wYitqSpc2G0e4g@mail.gmail.com> <471561516635427@web43o.yandex.ru>

* 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