X-Original-To: pgsql-general-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.144]) by svr1.postgresql.org (Postfix) with ESMTP id AC5783A49EA for ; Fri, 29 Oct 2004 00:22:03 +0100 (BST) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 83881-10 for ; Thu, 28 Oct 2004 23:21:55 +0000 (GMT) Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by svr1.postgresql.org (Postfix) with ESMTP id 077C03A4802 for ; Fri, 29 Oct 2004 00:21:57 +0100 (BST) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.1/8.13.1) with ESMTP id i9SNLqpC004233 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Thu, 28 Oct 2004 17:21:55 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.1/8.13.1) with ESMTP id i9SNLqNp076217; Thu, 28 Oct 2004 17:21:52 -0600 (MDT) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.1/8.13.1/Submit) id i9SNLqBu076216; Thu, 28 Oct 2004 17:21:52 -0600 (MDT) (envelope-from mfuhr) Date: Thu, 28 Oct 2004 17:21:52 -0600 From: Michael Fuhr To: "Jim C. Nasby" Cc: pgsql-general@postgresql.org Subject: Re: Turning a subselect into an array Message-ID: <20041028232152.GA76168@winnie.fuhr.org> References: <20041028223729.GF55164@decibel.org> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20041028223729.GF55164@decibel.org> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, hits=0.3 tagged_above=0.0 required=5.0 tests=UPPERCASE_25_50 X-Spam-Level: X-Archive-Number: 200410/1424 X-Sequence-Number: 67947 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/