From: | Steve Crawford <scrawford(at)pinpointresearch(dot)com> |
---|---|
To: | SZUCS Gábor <surrano(at)mailbox(dot)hu>, <pgsql-general(at)postgresql(dot)org> |
Subject: | Re: Arrays: determining size |
Date: | 2002-12-02 19:56:06 |
Message-ID: | 20021202195606.499A3103C7@polaris.pinpointresearch.com |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-general |
Thanks - I had read that document but overlooked array_dims (I had looked for
such functions using \df in psql but array_dims isn't listed). The values
returned are not two-dimensional but rather a start:end element of an array
(see notes below).
Ideally I'd like to get a single int that is the size of the array rather
than the min and max element of the array that array_dims returns but I don't
see a built-in function that does that.
Test notes: by default arrays in Postgresql start with element 1 but they
don't have to so the array dims appear to be the min and max element of the
array. If I add an adjacent element:
update foo set bar[0] = '{"test"}' where id=1;
I get:
select array_dims(bar) from foo;
[0:2]
Similarly
update foo set bar[-1] = '{"test"}' where id=1;
select array_dims(bar) from foo where id=1;
[-1:2]
Also, min() and max() seem to report the array dimensions having the smallest
element or the largest element:
select max(array_dims(bar)) from foo;
[1:2]
select min(array_dims(bar)) from foo;
[-1:2]
Thanks,
Steve
On Monday 02 December 2002 10:48 am, SZUCS Gábor wrote:
> Steve,
>
> It worked for me in 7.2.1:
>
> select *, array_dims(bar) from foo;
> bar | array_dims
> -----------+------------
> {1,2,3,4} | [1:4]
> {a,b,c} | [1:3]
> (2 rows)
>
> I think it's two-dimensional; read more in arrays.html in the PostgreSQL
> doc.
>
> G.
From | Date | Subject | |
---|---|---|---|
Next Message | Medi Montaseri | 2002-12-02 20:05:45 | Re: What could cause total crash of a postgres installation? |
Previous Message | Magnus Naeslund(f) | 2002-12-02 19:46:39 | Re: 7.4 Wishlist |