Re: creating array of integer[] out of query - how?

From: Sam Mason <sam(at)samason(dot)me(dot)uk>
To: pgsql-general(at)postgresql(dot)org
Subject: Re: creating array of integer[] out of query - how?
Date: 2009-09-02 10:03:33
Message-ID: 20090902100333.GN5407@samason.me.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On Wed, Sep 02, 2009 at 11:50:38AM +0200, Massa, Harald Armin wrote:
> select array(
> > select x from (
> > select array[2,3] as a
> > union
> > select array[3,4] as a ) x);
> >
> > ERROR: could not find array type for datatype record
>
> ... I remember being there before :( arrays of rows are also not available.

Doh, sorry I forgot that that's an 8.4 only. Before that you must
create your own composite type.

> To all: is there a deeper reason why there is no array type for datatype
> record available?

Not enough demand :)

> [1] http://www.postgresql.org/docs/current/static/sql-createtype.html
> >
> > Thanks for the hint with CREATE TYPE, especially the lines
>
> """
> Whenever a user-defined type is created, PostgreSQL automatically creates an
> associated array type,
> """
> fills me with joy. ;)

Try:

CREATE TYPE intarr AS (arr int[]);
SELECT array(
SELECT x::intarr FROM (
SELECT array[2,3]
UNION ALL
SELECT array[3,4]) x(a));

and it should do the right thing in 8.3.

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

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Devrim GÜNDÜZ 2009-09-02 10:23:51 Re: Ungooglable error message when running initdb: Symbol not found: _check_encoding_conversion_args
Previous Message Massa, Harald Armin 2009-09-02 09:50:38 Re: creating array of integer[] out of query - how?