When I execute the following query I would expect the results to be two of the same number. But it is two different numbers.
with t as (SELECT RAND())
SELECT * FROM t
UNION ALL
SELECT * FROM t;
I was using a similar process to try to randomize treatment and control and I thought the CTE was storing results, but it seems like it is storing a reference to a function and the function re-rolls the rand() every time it is queried later in the CTE chain. Why are the numbers not the same?
New contributor
Christopher Junk is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.