Search Postgresql Archives

Re: pg SQL question

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Sat, Jan 22, 2005 at 02:03:58PM -0700, Ed L. wrote:
> 
> There's probably an obvious answer for this, but I couldn't see it in the 
> docs.  What's the simplest way to concatenate multiple same-column values 
> in SQL?

You can create an aggregate that does nothing but concatenate the entries:

CREATE AGGREGATE concat (
    BASETYPE = TEXT,
    SFUNC = textcat,
    STYPE = TEXT,
    INITCOND = ''
);

This uses the "textcat" function, which is already lurking in Postgres to
implement the || operator. Then you can go:

SELECT concat(entry) FROM (
	SELECT * FROM speech ORDER BY id
) AS lines;

And it will do what you want. The subselect with the ORDER BY guarantees
that the lines come out in the order you put them in.


Richard

---------------------------(end of broadcast)---------------------------
TIP 8: explain analyze is your friend

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Index of Archives]     [Postgresql Jobs]     [Postgresql Admin]     [Postgresql Performance]     [Linux Clusters]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Books]     [PHP Databases]     [Postgresql & PHP]     [Yosemite]
  Powered by Linux