470,581 Members | 2,460 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,581 developers. It's quick & easy.

merge multiple records into 1

What would be the best way to "flatten" a set of records into one column with a query?

example:

You have a table called tbletters

id letters
1 a
2 b
3 c
4 d

So I can return this as one column in one record

a,b,c,d


---------------------------(end of broadcast)---------------------------TIP 3: if posting/reading through Usenet, please send an appropriate subscribe-nomail command to ma*******@postgresql.org so that your message can get through to the mailing list cleanly

Nov 11 '05 #1
2 2666
On Sat, Aug 23, 2003 at 20:16:51 -0400,
Brian Maguire <bm******@vantage.com> wrote:
What would be the best way to "flatten" a set of records into one column with a query?

example:

You have a table called tbletters

id letters
1 a
2 b
3 c
4 d

So I can return this as one column in one record

a,b,c,d


You could write an aggregate function that concatenates strings. There should
even be examples of some code that does this in the archives from within
the last 6 months.

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

Nov 11 '05 #2
CoL
Hi,

how about tablefunc_crosstab from contrib/tablefunc ?

Brian Maguire wrote, On 8/24/2003 2:16 AM:
What would be the best way to "flatten" a set of records into one column with a query?

example:

You have a table called tbletters

id letters
1 a
2 b
3 c
4 d

So I can return this as one column in one record

a,b,c,d

C.

Nov 11 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Morris | last post: by
1 post views Thread by achintya.jha | last post: by
1 post views Thread by law | last post: by
3 posts views Thread by cdelarte | last post: by
6 posts views Thread by crealesmith | last post: by
1 post views Thread by livre | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.