pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
select by groups
2+ messages / 2 participants
[nested] [flat]

* select by groups
@ 2004-03-01 22:20  Martin Marques <martin@bugs.unl.edu.ar>
  0 siblings, 1 reply; 2+ messages in thread

From: Martin Marques @ 2004-03-01 22:20 UTC (permalink / raw)
  To: pgsql-sql

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?

-- 
 19:15:01 up 97 days,  1:24,  4 users,  load average: 0.00, 0.07, 0.17
-----------------------------------------------------------------
Martín Marqués        | select 'mmarques' || '@' || 'unl.edu.ar'
Centro de Telematica  |  DBA, Programador, Administrador
             Universidad Nacional
                  del Litoral
-----------------------------------------------------------------




^ permalink  raw  reply  [nested|flat] 2+ messages in thread

* Re: select by groups
@ 2004-03-01 22:32  Manuel Sugawara <masm@fciencias.unam.mx>
  parent: Martin Marques <martin@bugs.unl.edu.ar>
  0 siblings, 0 replies; 2+ messages in thread

From: Manuel Sugawara @ 2004-03-01 22:32 UTC (permalink / raw)
  To: Martin Marques <martin@bugs.unl.edu.ar>; +Cc: pgsql-sql

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.



^ permalink  raw  reply  [nested|flat] 2+ messages in thread


end of thread, other threads:[~2004-03-01 22:32 UTC | newest]

Thread overview: 2+ messages (download: mbox mbox.gz follow: Atom feed)
-- links below jump to the message on this page --
2004-03-01 22:20 select by groups Martin Marques <martin@bugs.unl.edu.ar>
2004-03-01 22:32 ` Manuel Sugawara <masm@fciencias.unam.mx>

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