Matching dimensions in arrays
Matching dimensions in arrays
От:
Scara Maccai <m_lists@yahoo.it>
Дата:
Hi, nobody answered on the regular mailing list, hope someone can answer here Thank you -------- Original Message -------- Subject: [GENERAL] Matching dimensions in arrays Date: Mon, 9 Mar 2009 01:14:57 -0700 (PDT) From: Scara Maccai To: pgsql-general I've altready asked this some months ago, but I've never seen any answers: why do multidimensional arrays have to have matching extents for each dimension? Is there any way this limit can be removed, even using a custom datatype?
Re: Matching dimensions in arrays
От:
Sam Mason <sam@samason.me.uk>
Дата:
On Wed, Mar 25, 2009 at 12:58:46AM -0700, Scara Maccai wrote: > I've altready asked this some months ago, but I've never seen any answers: > > why do multidimensional arrays have to have matching extents for each > dimension? Because the dimensions define the rectangular bounds of the array in n-dimensional space and not some arbitrarily complex shape. This would be different from, say, Java where an array is always in 1-dimensional space and to "simulate" n-dimensional arrays you have arrays whose elements point to other arrays. These are semantically different things but modern languages choose to blur the distinction for reasons of simplicity. > Is there any way this limit can be removed, even using a custom datatype? What you're after is a way to have arrays of arrays; I could do the following to get it sort of working: CREATE TABLE foo ( a INT[] ); INSERT INTO foo VALUES (ARRAY[1,2,3]); INSERT INTO foo VALUES (ARRAY[9]); INSERT INTO foo VALUES (ARRAY[100,101,102,103,104]); SELECT ARRAY(SELECT foo FROM foo); SELECT (ARRAY(SELECT foo FROM foo))[1].a[1]; it's not very pretty or nice to work with (the literals look especially nasty) but it seems to hold together (in 8.3 at least). Sam