From: | Greg Stark <stark(at)enterprisedb(dot)com> |
---|---|
To: | John Lister <john(dot)lister-ps(at)kickstone(dot)com> |
Cc: | Andrew Chernow <ac(at)esilo(dot)com>, pgsql-hackers(at)postgresql(dot)org |
Subject: | Re: Array types |
Date: | 2009-04-08 15:35:00 |
Message-ID: | 4136ffa0904080835h76463e3bqfc4b87659e78ceed@mail.gmail.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-hackers |
On Wed, Apr 8, 2009 at 4:11 PM, John Lister
<john(dot)lister-ps(at)kickstone(dot)com> wrote:
> Cheers for the pointers. Am i right in thinking that if i get an array of
> arrays, the nested arrays are sent in wire format as well - it seems to be
> from the docs.
No, you can't easily get an array of arrays in Postgres. You can get
multi-dimensional arrays but that's one big array with multiple
dimensions. The text output form does look like an array of arrays
but they don't behave like you might think they would:
postgres=# select array[array[1,2,3,4],array[5,6,7,8]];
array
-----------------------
{{1,2,3,4},{5,6,7,8}}
(1 row)
postgres=# select '{{1,2,3,4},{5,6,7,8}}'::int[];
int4
-----------------------
{{1,2,3,4},{5,6,7,8}}
(1 row)
postgres=# select ('{{1,2,3,4},{5,6,7,8}}'::int[])[1];
int4
------
(1 row)
postgres=# select ('{{1,2,3,4},{5,6,7,8}}'::int[])[1][1];
int4
------
1
(1 row)
>
> Secondly, comments are a bit scarse in the code, but am i also right in
> thinking that an array indexing can start at an arbitrary value? This seems
> to be what the lbound value is for... or is this a addition to deal with
> nulls eg, {null, null, null, 4} would have a lbound of 3.... (or both)
No, nulls are handled using a bitmap inside the array data structure.
Array bounds don't have to start at 1, they can start below 1 or above 1.
postgres=# select ('[-2:-1][5:8]={{1,2,3,4},{5,6,7,8}}'::int[])[-2][5];
int4
------
1
(1 row)
--
greg
From | Date | Subject | |
---|---|---|---|
Next Message | Kevin Field | 2009-04-08 15:35:52 | Re: plpgsql debugger (pldbg) absent from 8.4? |
Previous Message | Tom Lane | 2009-04-08 15:33:38 | Re: Array types |