X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.192]) by svr1.postgresql.org (Postfix) with ESMTP id 75ED0CCE04 for ; Fri, 18 Jul 2003 21:36:07 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (svr4.postgresql.org [64.117.224.192]) (amavisd-new, port 10024) with ESMTP id 36716-06 for ; Fri, 18 Jul 2003 21:36:36 +0000 (GMT) Received: from joeconway.com (66-146-172-86.skyriver.net [66.146.172.86]) by svr1.postgresql.org (Postfix) with ESMTP id C2CE7CCE1C for ; Fri, 18 Jul 2003 18:36:04 -0300 (ADT) Received: from [206.19.64.3] (account jconway HELO joeconway.com) by joeconway.com (CommuniGate Pro SMTP 4.0.6) with ESMTP-TLS id 1827526; Fri, 18 Jul 2003 14:02:21 -0700 Message-ID: <3F1867F3.7000109@joeconway.com> Date: Fri, 18 Jul 2003 14:34:43 -0700 From: Joe Conway User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.0; en-US; rv:1.3) Gecko/20030312 X-Accept-Language: en-us, en MIME-Version: 1.0 To: miker@n2bb.com Cc: pgsql-sql@postgresql.org Subject: Re: casting to arrays References: <200307181707.48441.miker@n2bb.com> In-Reply-To: <200307181707.48441.miker@n2bb.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200307/263 X-Sequence-Number: 14377 Mike Rylander wrote: > I have a rather odd table structure that I would like to simplify to be a view > (for some definition of simplify). The current idea I have is to shovel > values from multiple rows in one table into an array in the view. The tables > look something like this: > > > Is anything like this possible? I know this may not be good form, but > unfortunately (or perhaps fortunately, since it means I have a job) there are > business reasons for this, supporting old apps and such. > Not possible in current releases, but it will be in 7.4 (about to start beta). It looks like this: create table person (id integer, name varchar); insert into person values(1,'Bob'); insert into person values(2,'Sue'); create table stuff (person_id integer, stuff_name text); insert into stuff values(1,'chair'); insert into stuff values(1,'couch'); insert into stuff values(1,'lamp'); insert into stuff values(2,'table'); insert into stuff values(2,'shirt'); create or replace view person_with_stuff as select p.id as id, p.name as name, ARRAY(select s.stuff_name from stuff s where s.person_id = p.id) as stuff from person p; regression=# select * from person_with_stuff; id | name | stuff ----+------+-------------------- 1 | Bob | {chair,couch,lamp} 2 | Sue | {table,shirt} (2 rows) HTH, Joe