Re: Matching dimensions in arrays

From: Sam Mason <sam(at)samason(dot)me(dot)uk>
To: pgsql-hackers(at)postgresql(dot)org
Subject: Re: Matching dimensions in arrays
Date: 2009-03-25 12:44:08
Message-ID: 20090325124408.GB12225@frubble.xen.chris-lamb.co.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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

In response to

Browse pgsql-hackers by date

  From Date Subject
Next Message Zdenek Kotala 2009-03-25 12:54:05 Re: DTrace probes broken in HEAD on Solaris?
Previous Message Peter Eisentraut 2009-03-25 12:35:48 SSL over Unix-domain sockets