Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1Umi9n-0004QM-O7 for pgsql-bugs@arkaria.postgresql.org; Wed, 12 Jun 2013 10:20:00 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.72) (envelope-from ) id 1Umi9n-0005QT-4I for pgsql-bugs@arkaria.postgresql.org; Wed, 12 Jun 2013 10:19:59 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.72) (envelope-from ) id 1Umi9l-0005QN-H2 for pgsql-bugs@postgresql.org; Wed, 12 Jun 2013 10:19:58 +0000 Received: from nm18.bullet.mail.ird.yahoo.com ([77.238.189.71]) by makus.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1Umi9i-0008LF-RR for pgsql-bugs@postgresql.org; Wed, 12 Jun 2013 10:19:56 +0000 Received: from [77.238.189.51] by nm18.bullet.mail.ird.yahoo.com with NNFMP; 12 Jun 2013 10:19:53 -0000 Received: from [46.228.39.98] by tm4.bullet.mail.ird.yahoo.com with NNFMP; 12 Jun 2013 10:19:53 -0000 Received: from [127.0.0.1] by smtp135.mail.ir2.yahoo.com with NNFMP; 12 Jun 2013 10:19:53 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.com; s=s1024; t=1371032393; bh=p1+wRTKuZGkSotNwzSZ1cmWS4vNy0Ueukahh77MrsEs=; h=X-Yahoo-Newman-Id:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:X-Rocket-Received:Content-Type:Mime-Version:Subject:From:In-Reply-To:Date:Content-Transfer-Encoding:Message-Id:References:To:X-Mailer; b=d0OuONA6Oy2WyO5sX3m7sYuYZF+/rTJ7yGXaN0QJwHWrnZNXOZ6L/WqRwsviaZpFW3LAkhZOQTWrRo8YEGC12rtNrULtckEe2XQN1qOn4oARKykVEeEsj7Bv5xKhenBCZ43UryRqfX+fRaObFUbTSZgxWyXrOM1O3sPO5wLx+ZI= X-Yahoo-Newman-Id: 482600.80116.bm@smtp135.mail.ir2.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: wL1TyKsVM1mn8dC.9UrFNWxR0Mz78dSU5IAo86B1SPWlvRx p73Hnyq9rF8EYB_5gLm8lv8vzzfWYCKQXbum.UpU5ey8GfRLecJUY3a9dNia zX9WrjQXOFOeBK016X5_rVzMCqP9QBPrT3oy_fTNCoPSzy_HTsM8c9HilAul _CcpmBDgfpdjRWuXfWAwiWq4tqt_HYLPVmrppoj6ktVw_5DKR7QbjtiMf1Xj AYbVFkvg4sHnHEFT2La47dTOXpGcwOMNvjq_yuK.Gm5hKa8lwisc37d_R.yz AHG7NVwhaPJkPE7_8jIMaod.C6wwViplK3XXm9OPuzQdb9A8vQ_xQJWGeOq. 89GhB2.V4LeZHFo8Q5zItdqI8hc_u3ogbW42pmPGFTY.c8Ait6DmhzXwLXkX htDuFpb3N0LOq_jx4N7oO4xt9qkpyQGOghKd.tXKHv03eTbf6o1cWPf11BG0 kzZXRqooGtefUstLiRtmiymSt71ssGDg3XQ-- X-Yahoo-SMTP: uVJuASqswBCGl3iGNbtCODeiD5FpnrTf X-Rocket-Received: from db.lan (ddebernardy@78.133.14.113 with ) by smtp135.mail.ir2.yahoo.com with SMTP; 12 Jun 2013 10:19:53 +0000 UTC Content-Type: text/plain; charset=windows-1252 Mime-Version: 1.0 (Apple Message framework v1283) Subject: Re: BUG #8226: Inconsistent unnesting of arrays From: Denis de Bernardy In-Reply-To: Date: Wed, 12 Jun 2013 12:19:51 +0200 Content-Transfer-Encoding: quoted-printable Message-Id: <336D0D5D-A04D-4E71-B78F-484017B74F81@yahoo.com> References: To: pgsql-bugs@postgresql.org X-Mailer: Apple Mail (2.1283) X-Pg-Spam-Score: 0.5 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-bugs Precedence: bulk Sender: pgsql-bugs-owner@postgresql.org The actual query was something like: select id, person, unnest(groups) as grp from people =85 where groups is a crazy column containing an array that needed to be jo= ined with another table. In this case, you cannot do your suggested solutio= n, which would look like this: select id, person, grp from people, unnest(groups) as grp Admittedly, there are other ways to rewrite the above, but =97 if I may =97= that's entirely besides the point of the bug report. The Stack Overflow qu= estion got me curious about what occurred when two separate arrays are unne= sted. Testing revealed the inconsistency, which I tend to view as a bug. This statement works as expected, unnesting the first array, then cross joi= ning the second accordingly: >> select 1 as a, unnest('{2,3}'::int[]) as b, unnest('{4,5,6}'::int[]) This seems to only unnest one of the arrays, and match the element with the= same subscript in the other array: >> select 1 as a, unnest('{2,3}'::int[]) as b, unnest('{4,5}'::int[]) Methinks the behavior should be consistent. It should always do one (presum= ably like in the first statement) or the other (which leads to undefined be= havior in the first statement). Or it should raise some kind of warning, e.g. "you're using undocumented/un= supported/deprecated/broken syntactic sugar". Denis On Jun 12, 2013, at 12:05 PM, Greg Stark wrote: > On Wed, Jun 12, 2013 at 9:58 AM, wrote: >> denis=3D# select 1 as a, unnest('{2,3}'::int[]) as b, unnest('{4,5}'::in= t[]) >=20 > set returning functions in the target list of the select don't behave > the way you're thinking. What you probably want to do is move the > unnest() to the FROM clause: >=20 > select 1 as a, b, c from unnest('{2,3}'::int[]) as b(b), > unnest('{4,5}'::int[]) as c(c) >=20 >=20 > --=20 > greg --=20 Sent via pgsql-bugs mailing list (pgsql-bugs@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-bugs