Re: unnest with generate_subscripts and same array

From: "David Johnston" <polobo(at)yahoo(dot)com>
To: "'Carlos Fuentes'" <caf(at)rentrakmail(dot)com>, <pgsql-general(at)postgresql(dot)org>
Subject: Re: unnest with generate_subscripts and same array
Date: 2011-05-27 00:58:57
Message-ID: 003101cc1c09$42b39310$c81ab930$@yahoo.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Can't speak to guarantees but arrays, unlike tuples / rows, are inherently
ordered and so any operation that decomposes/iterates them will do so in the
internal order.

So, yes.

(without looking at code)

But, since you do not have an "ORDER BY on table_with_array_col" so the
order in which rows are returned from table_with_array_col is undefined.
Better to write:

SELECT unnest(array_col), generate_subscripts(array_col)

FROM (

SELECT array_col FROM table_with_array_col ORDER BY somefield

) sub

David J.

From: pgsql-general-owner(at)postgresql(dot)org
[mailto:pgsql-general-owner(at)postgresql(dot)org] On Behalf Of Carlos Fuentes
Sent: Thursday, May 26, 2011 8:17 PM
To: pgsql-general(at)postgresql(dot)org
Subject: [GENERAL] unnest with generate_subscripts and same array

Hello,

Given that these are the only one array_col in play, is

select unnest(array_col), generate_subscripts(array_col) from
table_with_array_col ;

guaranteed to gave the subscripts match the array element? In all the
testing I've done it's worked, but I don't know if I was just lucky :)

Thanks,

-Carlos Fuentes

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Jasen Betts 2011-05-27 03:53:16 Re: 500KB PDF saving into large object , what is the table size?
Previous Message Carlos Fuentes 2011-05-27 00:17:06 unnest with generate_subscripts and same array