Re: Arrays: determining size
От | Steve Crawford |
---|---|
Тема | Re: Arrays: determining size |
Дата | |
Msg-id | 20021202195606.499A3103C7@polaris.pinpointresearch.com обсуждение исходный текст |
Ответ на | Re: Arrays: determining size (SZUCS Gábor <surrano@mailbox.hu>) |
Ответы |
Re: Arrays: determining size
|
Список | 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.
В списке pgsql-general по дате отправления: