Re: creating array of integer[] out of query - how? - Mailing list pgsql-general

From Sam Mason
Subject Re: creating array of integer[] out of query - how?
Date
Msg-id 20090902094014.GM5407@samason.me.uk
Whole thread Raw
In response to creating array of integer[] out of query - how?  ("Massa, Harald Armin" <chef@ghum.de>)
Responses Re: creating array of integer[] out of query - how?
List pgsql-general
On Wed, Sep 02, 2009 at 10:34:31AM +0200, Massa, Harald Armin wrote:
> postgres=# select array[[2,3],[3,4]];
>      array
> ---------------
>  {{2,3},{3,4}}
>
> -> the result looks for me as an array of integer-arrays

No, as depesz says it's not doing that.  Depending on what you want out
you can get most of the way by having an array of ROWs that contain an
array of integers.  You just need to change:

> select array(
> select a from (
> select array[2,3] as a
> union
> select array[3,4] as a ) x);

to return "x" instead of "a" in the inner select.  Something like:

  select array(
  select x from (
  select array[2,3] as a
  union
  select array[3,4] as a ) x);

getting the resulting tuples out again is a bit of a struggle and you
may be better off with using a custom type.  Have a look at CREATE
TYPE[1] for this.

--
  Sam  http://samason.me.uk/

 [1] http://www.postgresql.org/docs/current/static/sql-createtype.html

pgsql-general by date:

Previous
From: hubert depesz lubaczewski
Date:
Subject: Re: creating array of integer[] out of query - how?
Next
From: "Markus Wanner"
Date:
Subject: PostgreSQL Conference 2009 Japan