Re: Return relation table data in a single value CSV

From: Richard Huxton <dev(at)archonet(dot)com>
To: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
Cc: terry(at)ashtonwoodshomes(dot)com, "Postgresql Sql Group (E-mail)" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: Return relation table data in a single value CSV
Date: 2004-02-18 09:29:42
Message-ID: 200402180929.42103.dev@archonet.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

On Tuesday 17 February 2004 23:33, Tom Lane wrote:
> Richard Huxton <dev(at)archonet(dot)com> writes:
> > 2. Write a custom aggregate function (like sum()) to do the
> > concatenation. This is easy to do, but the order your ABC get processed
> > in is undefined.
>
> Actually, as of 7.4 it is possible to control the order of inputs to a
> custom aggregate. You do something like this:
>
> SELECT foo, myagg(bar) FROM
> (SELECT foo, bar FROM table ORDER BY foo, baz) AS ss
> GROUP BY foo
>
> The inner sub-select must order by the columns that the outer will group
> on; it can then order by additional columns that determine the sort
> order within each group. Here, myagg() will see its input ordered by
> increasing values of baz.

Hmm - good to know, but I'm always wary of doing this sort of thing. It's
exactly the sort of trick I look at 18 months later, fail to read my own
comments and "tidy" it.

--
Richard Huxton
Archonet Ltd

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Richard Huxton 2004-02-18 09:40:16 Re: CHAR(n) always trims trailing spaces in 7.4
Previous Message Achilleus Mantzios 2004-02-18 07:18:16 Re: bytea or blobs?