Re: UNNEST result order vs Array data

From: Richard Huxton <dev(at)archonet(dot)com>
To: Achilleas Mantzios <achill(at)matrix(dot)gatewaynet(dot)com>
Cc: pgsql-sql(at)postgresql(dot)org
Subject: Re: UNNEST result order vs Array data
Date: 2013-06-20 11:37:57
Message-ID: 51C2E995.3070407@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

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

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Vik Fearing 2013-06-20 12:11:35 Re: UNNEST result order vs Array data
Previous Message Achilleas Mantzios 2013-06-20 11:15:13 Re: UNNEST result order vs Array data