From: Tom Lane <tgl@sss.pgh.pa.us>
To: andrew@tao11.riddles.org.uk
Cc: pgsql-bugs@postgresql.org
Subject: Re: BUG #7622: Incorrect aggregate level processing
Date: Fri, 26 Oct 2012 09:44:44 -0400
Message-ID: <20677.1351259084@sss.pgh.pa.us> (raw)
In-Reply-To: <E1TRcLP-0008GF-Sp@wrigleys.postgresql.org>
References: <E1TRcLP-0008GF-Sp@wrigleys.postgresql.org>
andrew@tao11.riddles.org.uk writes:
> select (select array_agg(random()*i) from (values (1),(2)) v(a)) from
> generate_series(1,3) i;
> Expected output is three rows each with a 2-element array; actual output
> is:
> ERROR: more than one row returned by a subquery used as an expression
> Looking at the explain, the aggregate is being pulled out of the subplan and
> evaluated at the top query level. (This came up while doing some random data
> generation, I've simplified it a bit.)
This is not a bug, it's the behavior required by SQL standard. An
aggregate belongs to the lowest query level supplying a variable to it
(except of course when it contains no variable at all). So it's
effectively an outer-reference constant for that inner select.
regards, tom lane
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients from your mail client; the link fills in
the headers below: reply via email
Some clients, webmail especially, drop In-Reply-To and References from
a link, and the reply then starts a new thread: use the mbox below.
To: pgsql-bugs@postgresql.org
Cc: tgl@sss.pgh.pa.us, andrew@tao11.riddles.org.uk
Subject: Re: BUG #7622: Incorrect aggregate level processing
In-Reply-To: <20677.1351259084@sss.pgh.pa.us>
References: <E1TRcLP-0008GF-Sp@wrigleys.postgresql.org> <20677.1351259084@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox