Re: Collection

From: Raymond O'Donnell <rod(at)iol(dot)ie>
To: Ramesh T <rameshparnanditech(at)gmail(dot)com>, Adrian Klaver <adrian(dot)klaver(at)aklaver(dot)com>, pavel(dot)stehule(at)gmail(dot)com, "pgsql-general(at)postgresql(dot)org" <pgsql-general(at)postgresql(dot)org>
Subject: Re: Collection
Date: 2015-02-13 17:10:20
Message-ID: 54DE2FFC.10905@iol.ie
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

On 13/02/2015 13:13, Ramesh T wrote:
> cast(COLLECT (r_id) as num) in oracle..
>
> is their *collect *function in postgres plpgsql....?or any alternate
> for this..?

I don't use Oracle, but I think array_agg() is the closest - it
aggregates the column into an array.

postgres=# create table test(a integer, b text);
CREATE TABLE
postgres=# insert into test values (1, 'abc');
INSERT 0 1
postgres=# insert into test values (2, 'def');
INSERT 0 1
postgres=# insert into test values (2, 'ghi');
INSERT 0 1
postgres=# select a, array_agg(b) from test group by a;
a | array_agg
---+-----------
1 | {abc}
2 | {def,ghi}
(2 rows)

Ray.

--
Raymond O'Donnell :: Galway :: Ireland
rod(at)iol(dot)ie

In response to

Responses

Browse pgsql-general by date

  From Date Subject
Next Message Sergey Burladyan 2015-02-13 17:35:35 Contrib build fault for pgdg postgres 9.2 at debian 6 (squeeze)
Previous Message Seref Arikan 2015-02-13 16:56:27 Re: What's a reasonable maximum number for table partitions?