Collection

Started by Ramesh Tabout 11 years ago4 messagesgeneral
Jump to latest
#1Ramesh T
rameshparnanditech@gmail.com

cast(COLLECT (r_id) as num) in oracle..

is their *collect *function in postgres plpgsql....?or any alternate for
this..?

thanks in advance,

#2Pavel Stehule
pavel.stehule@gmail.com
In reply to: Ramesh T (#1)
Re: Collection

2015-02-13 14:13 GMT+01:00 Ramesh T <rameshparnanditech@gmail.com>:

COLLECT

Hi

Depends on what you needs. The collections are not supported by PostgreSQL
- use a arrays instead.

http://www.postgresql.org/docs/9.4/static/arrays.html

Regards

Pavel Stehule

In reply to: Ramesh T (#1)
Re: Collection

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@iol.ie

--
Sent via pgsql-general mailing list (pgsql-general@postgresql.org)
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general

#4Ramesh T
rameshparnanditech@gmail.com
In reply to: Raymond O'Donnell (#3)
Re: Collection

i solved my problem using string_agg in tab_to_string
ex:-
select string_agg(s.Rnumber ::text,',' )AS number

On Fri, Feb 13, 2015 at 10:40 PM, Raymond O'Donnell <rod@iol.ie> wrote:

Show quoted text

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@iol.ie