Re: Append n Rows into a Single Row

From: Samuel Gendler <sgendler(at)ideasculptor(dot)com>
To: Rob Sargent <robjsargent(at)gmail(dot)com>
Cc: Tripura <k_tripura(at)hotmail(dot)com>, pgsql-sql(at)postgresql(dot)org
Subject: Re: Append n Rows into a Single Row
Date: 2011-06-19 03:51:55
Message-ID: BANLkTim1GPLFqiTrXW695Hevvj4Bz8Ch=g@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-sql

Actually, you need the array_agg() function to aggregate multiple rows into
a single array, and that is discussed on the aggregate functions page,
here: http://www.postgresql.org/docs/9.0/static/functions-aggregate.html

You could then use one of the other array functions to manipulate that
array.

But given that you are appending strings to each other in your example, you
can also just use the string_agg function from that same page - assuming you
are on 9.0. It looks like that function isn't available before 9.0

--sam

On Sat, Jun 18, 2011 at 8:33 PM, Rob Sargent <robjsargent(at)gmail(dot)com> wrote:

> Look at the array aggregation functions here <http://www.postgresql.org/**
> docs/9.0/static/functions-**array.html<http://www.postgresql.org/docs/9.0/static/functions-array.html>
> >
>
>
> Tripura wrote:
>
>> Hi,
>> I am totally new to PostgreSQL and this is my first script.
>> Can anyone please help me with my following requirement
>> I have script that returns 1 column and 40 rows.
>> My requirement is update this existing script to show all the 40 rows data
>> in a single row as a string.
>>
>> For example The current script returns, something like this Tom
>> Tad
>> Max
>> Ted
>>
>> I have to update the existing script to show the above results as follow
>> Tom || Tad || Max || Ted
>> Something like colace in Ms sql
>>
>> Any help is really appriciated.
>>
>> Thankyou in Advance.
>>
>>
>>
>>
>>
>>
>>
>> --
>> View this message in context: http://postgresql.1045698.n5.**
>> nabble.com/Append-n-Rows-into-**a-Single-Row-**tp4500306p4500306.html<http://postgresql.1045698.n5.nabble.com/Append-n-Rows-into-a-Single-Row-tp4500306p4500306.html>
>> Sent from the PostgreSQL - sql mailing list archive at Nabble.com.
>>
>>
>>
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/**mailpref/pgsql-sql<http://www.postgresql.org/mailpref/pgsql-sql>
>

In response to

Responses

Browse pgsql-sql by date

  From Date Subject
Next Message Jasen Betts 2011-06-19 08:37:13 Re: pagination problem in postgresql need help
Previous Message Rob Sargent 2011-06-19 03:33:54 Re: Append n Rows into a Single Row