Re: Merging rows into one result?

From: Christopher Browne <cbbrowne(at)acm(dot)org>
To: pgsql-sql(at)postgresql(dot)org
Subject: Re: Merging rows into one result?
Date: 2006-03-11 17:00:27
Message-ID: 87wtf0kjbo.fsf@wolfe.cbbrowne.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Centuries ago, Nostradamus foresaw when jkp(at)solnet(dot)homeip(dot)net ("Jesper K. Pedersen") would write:
> Is it possible to use SQL to merge data into one result?
>
> A theorethical example to explain:
>
> tbl_test (
> id integer,
> information varchar(25))
>
> id | information
> ---+--------------
> 1 | Yo
> 2 | Go away
> 1 | Stay put
> 3 | Greetings
>
> Please note id is not unique and not a primary key.
>
> and I wonder if there is any functions to "merge" data (sort of
> concat'ing).
> A normal: select information from tbl_test where id=1
> would result in the rows
> Yo
> Stay put
>
> I would like a single row result in the format of:
> Yo Stay put
>
> Any ideas on this?

Sure, you could create a custom aggregate to append them using spaces.

Look in the PostgreSQL documentation under "CREATE AGGREGATE." If you
check the online version at PostgreSQL.org, there are comments showing
examples...
--
wm(X,Y):-write(X),write('@'),write(Y). wm('cbbrowne','gmail.com').
http://linuxdatabases.info/info/wp.html
--Despite Pending :Alarm--

In response to

Browse pgsql-sql by date

  From Date Subject
Next Message Weimao Ke 2006-03-12 05:09:48 pgsql aggregate: conditional max
Previous Message Jesper K. Pedersen 2006-03-11 16:58:26 Re: Merging rows into one result?