`order by random()` makes select-list `random()` invocations deterministic - Mailing list pgsql-bugs

From Dian Fay
Subject `order by random()` makes select-list `random()` invocations deterministic
Date
Msg-id CZHAF947QQQO.27MAUK2SVMBXW@nmfay.com
Whole thread Raw
Responses Re: `order by random()` makes select-list `random()` invocations deterministic  ("David G. Johnston" <david.g.johnston@gmail.com>)
List pgsql-bugs
In Postgres 16.1, running the following query:

```
select
  gs,
  gs + random() * 100 - 50 as gs2,
  random() * 100 - 50 as r1,
  random() * 100 - 50 as r2,
  random() * 100 - 50 as r3
from generate_series(0, 10) as gs
order by random();
```

Every `random()` invocation in the select list uses a single consistent
value within each returned row. Remove the `order by random()` and
values become randomized as expected, but it gets a bit stranger:

- order by any of the `rN` values and `gs2` uses a different random
  value, but all the `rN` values are identical;
- order by `gs2` and all random values are distinct again.



pgsql-bugs by date:

Previous
From: Andrei Lepikhov
Date:
Subject: Re: BUG #18349: ERROR: invalid DSA memory alloc request size 1811939328, CONTEXT: parallel worker
Next
From: Andrew Dunstan
Date:
Subject: Re: Feature bug dumpall CREATE ROLE postgres