Re: ARRAY(subquery) volatility - Mailing list pgsql-hackers

From Joe Conway
Subject Re: ARRAY(subquery) volatility
Date
Msg-id 43019822.2010405@joeconway.com
Whole thread Raw
In response to ARRAY(subquery) volatility  (Michael Fuhr <mike@fuhr.org>)
List pgsql-hackers
Michael Fuhr wrote:
> Why does the first query below return the same value for each row
> while the second query returns random values?  Planner optimization?

I assume it is due to some kind of flattening in the planner, but it is 
totally unrelated to ARRAY(subquery):

regression=# SELECT (SELECT random()) as f FROM generate_series(1, 5);         f
------------------- 0.752416231088534 0.752416231088534 0.752416231088534 0.752416231088534 0.752416231088534
(5 rows)

regression=# SELECT (SELECT random() + 0 * f) as f FROM 
generate_series(1, 5) as t(f);         f
------------------- 0.176055165555354 0.608546747178094  0.55303416240636 0.127355110425202  0.21671894063089
(5 rows)

Here's another example:

regression=# create table t1(f text);
CREATE TABLE
regression=# insert into t1 values('0');
INSERT 17366 1
regression=# insert into t1 values('0');
INSERT 17367 1
regression=# insert into t1 values('0');
INSERT 17368 1
regression=# SELECT (SELECT timeofday()::timestamp + f::interval) as f 
FROM t1;             f
---------------------------- 2005-08-16 16:38:12.738215 2005-08-16 16:38:12.738292 2005-08-16 16:38:12.738315
(3 rows)

regression=# SELECT (SELECT timeofday()::timestamp) as f FROM t1;             f
---------------------------- 2005-08-16 16:35:33.100791 2005-08-16 16:35:33.100791 2005-08-16 16:35:33.100791
(3 rows)

This shows that it isn't related to use of an SRF either.

Joe


pgsql-hackers by date:

Previous
From: Tino Wildenhain
Date:
Subject: Re: Testing of MVCC
Next
From: "Qingqing Zhou"
Date:
Subject: Re: Race conditions, race conditions!