Re: Matching dimensions in arrays - Mailing list pgsql-hackers

From Sam Mason
Subject Re: Matching dimensions in arrays
Date
Msg-id 20090325124408.GB12225@frubble.xen.chris-lamb.co.uk
Whole thread Raw
In response to Matching dimensions in arrays  (Scara Maccai <m_lists@yahoo.it>)
List pgsql-hackers
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


pgsql-hackers by date:

Previous
From: Peter Eisentraut
Date:
Subject: SSL over Unix-domain sockets
Next
From: Zdenek Kotala
Date:
Subject: Re: DTrace probes broken in HEAD on Solaris?