Re: Turning a subselect into an array - Mailing list pgsql-general

From Michael Fuhr
Subject Re: Turning a subselect into an array
Date
Msg-id 20041028232152.GA76168@winnie.fuhr.org
Whole thread Raw
In response to Turning a subselect into an array  ("Jim C. Nasby" <decibel@decibel.org>)
Responses Re: Turning a subselect into an array  ("Jim C. Nasby" <decibel@decibel.org>)
List pgsql-general
On Thu, Oct 28, 2004 at 05:37:29PM -0500, Jim C. Nasby wrote:
> I'm sure this has been answered before, but the search seems to be down
> again.
>
> How can I convert the results of a subselect into an array? IE:
>
> CREATE TABLE a(a int, b int, c int[]);
> INSERT INTO table_a
>     SELECT a, b, (SELECT c FROM table_c WHERE table_c.parent = table_b.id)
>         FROM table_b

See the "Array Constructors" section in the PostgreSQL documentation:

http://www.postgresql.org/docs/7.4/static/sql-expressions.html#SQL-SYNTAX-ARRAY-CONSTRUCTORS

INSERT INTO table_a
  SELECT a, b, ARRAY(SELECT c FROM table_c WHERE table_c.parent = table_b.id)
  FROM table_b

--
Michael Fuhr
http://www.fuhr.org/~mfuhr/

pgsql-general by date:

Previous
From: Robby Russell
Date:
Subject: Re: determine sequence name for a serial
Next
From: Jonathan Daugherty
Date:
Subject: Re: determine sequence name for a serial