Re: Concatenating string fields with GROUP BY clause - Mailing list pgsql-novice

From stork@vnet.hu (Vajda Gabor)
Subject Re: Concatenating string fields with GROUP BY clause
Date
Msg-id db7789b.0309131210.625da358@posting.google.com
Whole thread Raw
In response to Concatenating string fields with GROUP BY clause  ("Brian G. Huber" <brianghuber@yahoo.com>)
List pgsql-novice
Dear Brian!

You need to write an aggregate like this:

  CREATE AGGREGATE textcat_all(
      basetype    = text,
      sfunc       = textcat,
      stype       = text,
      initcond    = ''
  );

You can use this new aggregate in your query. For example:

  SELECT partner.name, textcat_all(phones.number || ', ')
      FROM partner LEFT JOIN phones ON partner.id = phones.partner_id
      GROUP BY partner.name;

Bye,

Gabor Vajda

brianghuber@yahoo.com ("Brian G. Huber") wrote in message news:<001b01c376f4$124dc410$6400a8c0@bghmobile>...
> Hi -
>
> I am trying to concatenate a text field in a query with a group by clause,
> similar to a sum() function on a numeric value - for example:
>
> SELECT groupid, sum(numeric field), ???(text field) FROM table GROUP BY gro
> upid
>
> but I cannot find a function that will concatenate the text fields. Any com
> ments appreciated!
>
> TIA,BGH
> --

pgsql-novice by date:

Previous
From: "Tony Colson"
Date:
Subject: User Customization Files
Next
From: marcin.gil@mail.vernet.pl
Date:
Subject: Re: operation logging