X-Original-To: pgsql-sql@postgresql.org Received: from localhost (postgresql.org [64.49.215.8]) by postgresql.org (Postfix) with ESMTP id D1FBB476189 for ; Tue, 25 Feb 2003 03:06:27 -0500 (EST) Received: from postgresql.org ([64.49.215.8]) by localhost (postgresql.org [64.49.215.8:10024]) (amavisd-new) with SMTP id 19705-02 for ; Tue, 25 Feb 2003 03:05:59 -0500 (EST) Received: from news.hub.org (news.hub.org [64.49.215.80]) by postgresql.org (Postfix) with ESMTP id 882D847630C for ; Mon, 24 Feb 2003 23:22:09 -0500 (EST) Received: by news.hub.org (Postfix, from userid 8) id 72BF443A945; Mon, 24 Feb 2003 23:22:09 -0500 (EST) From: no.spam@address.com X-Newsgroups: comp.databases.postgresql.sql Subject: Re: Denormalizing during select Message-ID: References: <200302241433.49502.josh@agliodbs.com> X-Newsreader: Forte Agent 1.91/32.564 MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Lines: 64 Date: Tue, 25 Feb 2003 03:37:41 GMT X-Complaints-To: abuse@cox.net Organization: Cox Communications To: pgsql-sql@postgresql.org X-Virus-Scanned: by amavisd-new X-Archive-Number: 200303/30 X-Sequence-Number: 12070 On Tue, 25 Feb 2003 01:22:42 +0000 (UTC), josh@agliodbs.com (Josh Berkus) wrote: >Can you post the start of this thread? I think there's a more >efficient way using custom aggregates, but somhow I never >received the original question. I'm hoping there is... somehow, using a function to loop over every row seems a bit inefficient? Here's my original question... I have two tables (A and B) in a one-to-many relationship. When retrieving data from one table (A), I need to denormalize the tables during a select so that values of a column in the many table (B) appear as a list in one field of the output. E.g.: create table one_table ( name varchar(20), age integer, -- constraint one_table_pk primary key (name) ); create table many_table ( name varchar(20), property varchar(15), -- constraint many_table_pk primary key (name, property), constraint many_table_fk foreign key (name) references one_table (name) ); So one_table could contain: name age ---- --- Mickey Mouse 50 Donald Duck 60 Goofy 45 and many_table could contain: name property ---- -------- Mickey Mouse Small Mickey Mouse Black Mickey Mouse Squeaks Donald Duck Quacks The query I'm trying to write would have as output something like: name age properties ---- --- ---------- Mickey Mouse 50 Small, Black, Squeaks Donald Duck 60 Quacks Goofy 45 Could somebody please help point me in the right direction? I imagine this is a common need... Thanks, ...Edmund.