From: Manuel Sugawara <masm@fciencias.unam.mx>
To: Martin Marques <martin@bugs.unl.edu.ar>
Cc: pgsql-sql@postgresql.org
Subject: Re: select by groups
Date: 01 Mar 2004 16:32:50 -0600
Message-ID: <m3ekscw63x.fsf@conexa.fciencias.unam.mx> (raw)
In-Reply-To: <200403011920.20505.martin@bugs.unl.edu.ar>
References: <200403011920.20505.martin@bugs.unl.edu.ar>
Martin Marques <martin@bugs.unl.edu.ar> 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.
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: masm@fciencias.unam.mx, martin@bugs.unl.edu.ar
Subject: Re: select by groups
In-Reply-To: <m3ekscw63x.fsf@conexa.fciencias.unam.mx>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox