Re: ARRAY(subquery) volatility

From: Joe Conway <mail(at)joeconway(dot)com>
To: Michael Fuhr <mike(at)fuhr(dot)org>
Cc: pgsql-hackers(at)postgresql(dot)org
Subject: Re: ARRAY(subquery) volatility
Date: 2005-08-16 07:39:14
Message-ID: 43019822.2010405@joeconway.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Qingqing Zhou 2005-08-16 07:46:22 Re: Race conditions, race conditions!
Previous Message Tino Wildenhain 2005-08-16 07:22:34 Re: Testing of MVCC