Received: from magus.postgresql.org ([2a02:c0:301:0:ffff::29]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TRcLY-00075P-KO for pgsql-bugs@postgresql.org; Fri, 26 Oct 2012 05:20:40 +0000 Received: from mahout.postgresql.org ([98.129.198.123]) by magus.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TRcLS-0005aX-2a for pgsql-bugs@postgresql.org; Fri, 26 Oct 2012 05:20:40 +0000 Received: from [204.145.124.246] (helo=wrigleys.postgresql.org) by mahout.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1TRcLQ-00068V-AM for pgsql-bugs@postgresql.org; Fri, 26 Oct 2012 05:20:33 +0000 Received: from www-data by wrigleys.postgresql.org with local (Exim 4.72) (envelope-from ) id 1TRcLP-0008GF-Sp for pgsql-bugs@postgresql.org; Fri, 26 Oct 2012 05:20:31 +0000 Date: Fri, 26 Oct 2012 05:20:31 +0000 Message-Id: Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: BUG #7622: Incorrect aggregate level processing To: pgsql-bugs@postgresql.org From: andrew@tao11.riddles.org.uk X-Pg-Spam-Score: -2.6 (--) X-Archive-Number: 201210/225 X-Sequence-Number: 34525 The following bug has been logged on the website: Bug reference: 7622 Logged by: Andrew Gierth Email address: andrew@tao11.riddles.org.uk PostgreSQL version: 9.2.1 Operating system: n/a Description: = Tested on git-master, 9.2.1, various older versions. 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.)