Received: from malur.postgresql.org ([217.196.149.56]) by arkaria.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1UpdBj-0006cd-Et for pgsql-sql@arkaria.postgresql.org; Thu, 20 Jun 2013 11:38:03 +0000 Received: from localhost ([127.0.0.1] helo=postgresql.org) by malur.postgresql.org with smtp (Exim 4.80) (envelope-from ) id 1UpdBi-0006fX-SL for pgsql-sql@arkaria.postgresql.org; Thu, 20 Jun 2013 11:38:02 +0000 Received: from makus.postgresql.org ([2001:4800:7903:4::125]) by malur.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1UpdBh-0006dg-8J for pgsql-sql@postgresql.org; Thu, 20 Jun 2013 11:38:01 +0000 Received: from archon2012.plus.com ([80.229.41.160] helo=mail.archonet.com) by makus.postgresql.org with esmtp (Exim 4.80) (envelope-from ) id 1UpdBe-0007g7-Uh for pgsql-sql@postgresql.org; Thu, 20 Jun 2013 11:38:00 +0000 Received: from [192.168.1.13] (ariel.office.archonet.com [192.168.1.13]) by mail.archonet.com (Postfix) with ESMTP id AB7E42C40F1; Thu, 20 Jun 2013 12:37:57 +0100 (BST) Message-ID: <51C2E995.3070407@archonet.com> Date: Thu, 20 Jun 2013 12:37:57 +0100 From: Richard Huxton User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:10.0.12) Gecko/20130116 Icedove/10.0.12 MIME-Version: 1.0 To: Achilleas Mantzios CC: pgsql-sql@postgresql.org Subject: Re: UNNEST result order vs Array data References: <1371724857304-5760087.post@n5.nabble.com> <51C2DD42.4000002@dalibo.com> <51C2E441.4020200@matrix.gatewaynet.com> In-Reply-To: <51C2E441.4020200@matrix.gatewaynet.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Pg-Spam-Score: 0.8 (/) List-Archive: List-Help: List-ID: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: X-Mailing-List: pgsql-sql Precedence: bulk Sender: pgsql-sql-owner@postgresql.org On 20/06/13 12:15, Achilleas Mantzios wrote: > On 20/06/2013 13:45, Vik Fearing wrote: >> On 06/20/2013 12:40 PM, gmb wrote: >>> Hi all >>> I just want to confirm something regarding UNNEST function used with >>> arrays. >>> I cannot see that it is specifically mentioned in the documentation , >>> but >>> maybe because it is obvious. >>> >>> Is the order of the result guaranteed to be the order of the array >> Order is never guaranteed unless you specify an ORDER BY clause. >> >> > I really think that the order should exactly reflect the order in the > array. > Think of ARRAY as Relation + ORDER. Relation + Order gives an ARRAY, > ARRAY should give Relation *and* ORDER in return. An array is ordered. If you turn it into a relation then it isn't ordered any more until you apply ORDER BY. An unnest() will almost certainly scan the array in-order, but once you embed that in a large query the ordering is no longer guaranteed. -- Richard Huxton Archonet Ltd -- Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org) To make changes to your subscription: http://www.postgresql.org/mailpref/pgsql-sql