X-Original-To: pgsql-sql-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [200.46.204.2]) by svr1.postgresql.org (Postfix) with ESMTP id 6A86ED1E2E6 for ; Mon, 1 Mar 2004 22:38:45 +0000 (GMT) Received: from svr1.postgresql.org ([200.46.204.71]) by localhost (neptune.hub.org [200.46.204.2]) (amavisd-new, port 10024) with ESMTP id 30536-04 for ; Mon, 1 Mar 2004 18:38:44 -0400 (AST) Received: from conexa.fciencias.unam.mx (conexa.fciencias.unam.mx [132.248.181.120]) by svr1.postgresql.org (Postfix) with ESMTP id BF864D1E14C for ; Mon, 1 Mar 2004 18:38:40 -0400 (AST) Received: from conexa.fciencias.unam.mx (conexa.fciencias.unam.mx [127.0.0.1]) by conexa.fciencias.unam.mx (8.12.8/8.12.8) with ESMTP id i21MWpiA003603; Mon, 1 Mar 2004 16:32:51 -0600 Received: (from masm@localhost) by conexa.fciencias.unam.mx (8.12.8/8.12.8/Submit) id i21MWoSP003601; Mon, 1 Mar 2004 16:32:50 -0600 X-Authentication-Warning: conexa.fciencias.unam.mx: masm set sender to masm@fciencias.unam.mx using -f To: Martin Marques Cc: pgsql-sql@postgresql.org Subject: Re: select by groups References: <200403011920.20505.martin@bugs.unl.edu.ar> In-Reply-To: <200403011920.20505.martin@bugs.unl.edu.ar> From: Manuel Sugawara User-Name: Manuel Sugawara User-Mail-Address: masm@fciencias.unam.mx Date: 01 Mar 2004 16:32:50 -0600 Message-ID: Lines: 23 User-Agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Portable Code) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200403/13 X-Sequence-Number: 17112 Martin Marques writes: > I have a table with names of people, email address, etc, and an identifier > that tells me which group they are in (could be a 1, 2, or 3 person group). > Is it posible to make a query that would give me the name of the persons of > each group in one row? Or do I have to do PL? Use GROUP BY with an aggregator that concatenate the names. The aggregator may be implemented in plpgsql, for instance: CREATE OR REPLACE FUNCTION concat (text, text) RETURNS text AS 'select case when $1 = '''' then $2 else ($1 || '', '' || $2) end' LANGUAGE sql; CREATE AGGREGATE concat ( BASETYPE = text, SFUNC = public.concat, STYPE = text, INITCOND = '' ); Regards, Manuel.