X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (av.hub.org [200.46.204.144]) by postgresql.org (Postfix) with ESMTP id D57589DC897 for ; Mon, 19 Dec 2005 12:54:57 -0400 (AST) Received: from postgresql.org ([200.46.204.71]) by localhost (av.hub.org [200.46.204.144]) (amavisd-new, port 10024) with ESMTP id 82619-06 for ; Mon, 19 Dec 2005 12:54:56 -0400 (AST) X-Greylist: from auto-whitelisted by SQLgrey- Received: from tigger.fuhr.org (tigger.fuhr.org [63.214.45.158]) by postgresql.org (Postfix) with ESMTP id 8EC319DC810 for ; Mon, 19 Dec 2005 12:54:54 -0400 (AST) Received: from winnie.fuhr.org (winnie.fuhr.org [10.1.0.1]) by tigger.fuhr.org (8.13.3/8.13.3) with ESMTP id jBJGsn9H094252 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK); Mon, 19 Dec 2005 09:54:52 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: from winnie.fuhr.org (localhost [127.0.0.1]) by winnie.fuhr.org (8.13.4/8.13.4) with ESMTP id jBJGsnea099864; Mon, 19 Dec 2005 09:54:49 -0700 (MST) (envelope-from mfuhr@winnie.fuhr.org) Received: (from mfuhr@localhost) by winnie.fuhr.org (8.13.4/8.13.4/Submit) id jBJGsnDv099863; Mon, 19 Dec 2005 09:54:49 -0700 (MST) (envelope-from mfuhr) Date: Mon, 19 Dec 2005 09:54:49 -0700 From: Michael Fuhr To: george young Cc: pgsql-sql@postgresql.org Subject: Re: how to convert relational column to array? Message-ID: <20051219165449.GA99764@winnie.fuhr.org> References: <20051219110612.26de2268.gry@ll.mit.edu> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20051219110612.26de2268.gry@ll.mit.edu> X-Virus-Scanned: by amavisd-new at hub.org X-Spam-Status: No, score=0.027 required=5 tests=[AWL=0.027] X-Spam-Score: 0.027 X-Spam-Level: X-Archive-Number: 200512/168 X-Sequence-Number: 23710 On Mon, Dec 19, 2005 at 11:06:12AM -0500, george young wrote: > create table new_tab(name text, id int, permits text[]); > > -- I insert one row per name: > insert into new_tab select distinct name,id,cast('{}' as text[]) from old_tab; > > Now I want to fold all the 'permits' values into the new permits arrays. In PostgreSQL 7.4 and later you can build an array from a select, so I think the following update should work (it did for me when I tested it): UPDATE new_tab SET permits = array( SELECT permits FROM old_tab WHERE old_tab.name = new_tab.name AND old_tab.id = new_tab.id ); -- Michael Fuhr