Search Postgresql Archives

Re: Using random() in update produces same random value for all

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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




[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]

  Powered by Linux