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

2018-01-23 Thread Olleg Samoylov
On 2018-01-22 23:15, Tom Lane wrote: > > 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

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

2018-01-22 Thread Tom Lane
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

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

2018-01-22 Thread Jeff Janes
On Mon, Jan 22, 2018 at 9:16 AM, Tom Lane wrote: > Olleg Samoylov writes: > > Looked like random() is "volatile", but in subselect it works like > "stable". > > The point here is that that's an uncorrelated subselect --- ie, it > contains no outer references

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

2018-01-22 Thread Tom Lane
Olleg Samoylov writes: > Looked like random() is "volatile", but in subselect it works like "stable". 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.

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

2018-01-22 Thread Olleg Samoylov
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   

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

2018-01-14 Thread Ken Tanzer
On Sun, Jan 14, 2018 at 2:01 AM, Alex Magnum wrote: > Hi, > i am trying to update a table with some random dates but that does not > seem to work. > > UPDATE table >SET last_update=now()::date-(SELECT (random() * 5)::INTEGER + 1) > > The updated field is always set to

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

2018-01-14 Thread Alex Magnum
Hi, i am trying to update a table with some random dates but that does not seem to work. UPDATE table SET last_update=now()::date-(SELECT (random() * 5)::INTEGER + 1) The updated field is always set to the same. Is there a way to make it random for every record? I could run it through a