Skip site navigation (1) Skip section navigation (2)

Re: Turning a subselect into an array

From: Michael Fuhr <mike(at)fuhr(dot)org>
To: "Jim C(dot) Nasby" <decibel(at)decibel(dot)org>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: Turning a subselect into an array
Date: 2004-10-28 23:21:52
Message-ID: 20041028232152.GA76168@winnie.fuhr.org (view raw or flat)
Thread:
Lists: pgsql-docspgsql-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/

In response to

Responses

pgsql-docs by date

Next:From: Wood, BruceDate: 2004-10-29 18:37:21
Subject: PREPARE statement example error.
Previous:From: Jim C. NasbyDate: 2004-10-28 22:37:29
Subject: Turning a subselect into an array

pgsql-general by date

Next:From: Jonathan DaughertyDate: 2004-10-28 23:25:10
Subject: Re: determine sequence name for a serial
Previous:From: Robby RussellDate: 2004-10-28 23:07:36
Subject: Re: determine sequence name for a serial

Privacy Policy | About PostgreSQL
Copyright © 1996-2014 The PostgreSQL Global Development Group