Thread: Arrays of arrays

Arrays of arrays

From
rsmogura
Date:
 Hello,

 May I ask if PostgreSQL supports arrays of arrays directly or
 indirectly, or if such support is planned? I'm interested about pseudo
 constructs like:
 1. Directly - (integer[4])[5] - this is equivalent to multidimensional
 array, but may be differently represented on protocol serialization (as
 array with array of elements).
 2. Indirectly - like create domain d as integer[6], d[11], or by any
 other means.

 Currently, I think both of this, are unsupported and array should be
 only base type. I ask about this, to create extend array support in
 JDBC.

 Regards,
 Radek.

Re: Arrays of arrays

From
Merlin Moncure
Date:
On Thu, Apr 7, 2011 at 4:39 AM, rsmogura <rsmogura@softperience.eu> wrote:
> Hello,
>
> May I ask if PostgreSQL supports arrays of arrays directly or indirectly, or
> if such support is planned? I'm interested about pseudo constructs like:
> 1. Directly - (integer[4])[5] - this is equivalent to multidimensional
> array, but may be differently represented on protocol serialization (as
> array with array of elements).
> 2. Indirectly - like create domain d as integer[6], d[11], or by any other
> means.
>
> Currently, I think both of this, are unsupported and array should be only
> base type. I ask about this, to create extend array support in JDBC.

if you want to do serialization of complex structures through the
protocol, your best bet currently is to use composites.  for example,
if you want to make array of arrays that are not all the same length
(if they were the same length, why not use regular array?):

create type t (i int[]);
select array[row(array[1,2])::t, row(array[1,2,3,4])::t];

merlin

Re: Arrays of arrays

From
Radosław Smogura
Date:
Merlin Moncure <mmoncure@gmail.com> Thursday 07 April 2011 15:53:00
> On Thu, Apr 7, 2011 at 4:39 AM, rsmogura <rsmogura@softperience.eu> wrote:
> > Hello,
> >
> > May I ask if PostgreSQL supports arrays of arrays directly or indirectly,
> > or if such support is planned? I'm interested about pseudo constructs
> > like: 1. Directly - (integer[4])[5] - this is equivalent to
> > multidimensional array, but may be differently represented on protocol
> > serialization (as array with array of elements).
> > 2. Indirectly - like create domain d as integer[6], d[11], or by any
> > other means.
> >
> > Currently, I think both of this, are unsupported and array should be only
> > base type. I ask about this, to create extend array support in JDBC.
>
> if you want to do serialization of complex structures through the
> protocol, your best bet currently is to use composites.  for example,
> if you want to make array of arrays that are not all the same length
> (if they were the same length, why not use regular array?):
>
> create type t (i int[]);
> select array[row(array[1,2])::t, row(array[1,2,3,4])::t];
>
> merlin

No, I'm asking due to development of driver, just I don't want to expose some
functionality that may cause problems in future, when arrays of arrays will be
available, so it's quite important.

Just one more topic to discussion: should zero length arrays, like int[5][0]
[6], be available? Or error should be thrown?

Regards,
Radek.