The following bug has been logged on the website:
Bug reference: 16121
Logged by: Elvis Pranskevichus
Email address: elprans@gmail.com
PostgreSQL version: 12.1
Operating system: Gentoo Linux
Description:
There seems to be a regression in Postgres 12 related to how volatile
functions are handled. If put inside a subquery in the target list, the
volatile function seems to behave like a stable one:
volatility=# SELECT
v.i,
(SELECT random() from (values (v.i)) as q) AS v1
FROM
generate_series(1, 2) as v(i);
i │ v1
───┼────────────────────
1 │ 0.8303615124282295
2 │ 0.8303615124282295
(2 rows)
Postgres 11 and earlier worked correctly:
volatility=# SELECT
v.i,
(SELECT random() from (values (v.i)) as q) AS v1
FROM
generate_series(1, 2) as v(i);
i │ v1
───┼───────────────────
1 │ 0.137472071684897
2 │ 0.288798084016889
(2 rows)