[HACKERS] Matching dimensions in arrays

2009-03-25 Thread Scara Maccai

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 m_li...@yahoo.it
To: pgsql-general pgsql-gene...@postgresql.org



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?





-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers


Re: [HACKERS] Matching dimensions in arrays

2009-03-25 Thread Sam Mason
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

-- 
Sent via pgsql-hackers mailing list (pgsql-hackers@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-hackers