From: | Olleg Samoylov <splarv(at)ya(dot)ru> |
---|---|
To: | "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 15:37:07 |
Message-ID: | 471561516635427@web43o.yandex.ru |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
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".
From | Date | Subject | |
---|---|---|---|
Next Message | Tom Lane | 2018-01-22 17:16:21 | Re: Using random() in update produces same random value for all |
Previous Message | Michael Krüger | 2018-01-22 15:24:29 | Slow alter sequence with PG10.1 |