Re: [GENERAL] Use of array_agg and array string on inner query

2016-05-19 Thread shankha
I got the query: SELECT c1, c2, ARRAY_TO_STRING(ARRAY_AGG((SELECT t3.c1 FROM s.t1 as t3 JOIN s.t1 as t2 ON t3.c3 = t2.c2)), ',') FROM s.t1 t1 GROUP BY c1; DROP SCHEMA s CASCADE; Thanks for all the help. Thanks Shankha Banerjee On Wed, May 18, 2016 at 2:40 PM, David G. Johnston wrote: > On We

Re: [GENERAL] Use of array_agg and array string on inner query

2016-05-18 Thread David G. Johnston
On Wed, May 18, 2016 at 2:30 PM, shankha wrote: > I cannot move the array_agg to around the column name. It has to work > as a inner query > ​. > ​The following form is used to make an array from a subquery: SELECT ARRAY(SELECT i FROM ( VALUES (1), (2), (3) ) vals (i) );​ ​ ​ http://www.postgr

Re: [GENERAL] Use of array_agg and array string on inner query

2016-05-18 Thread shankha
I cannot move the array_agg to around the column name. It has to work as a inner query. I will try out your other suggestion. Thanks Shankha Banerjee On Wed, May 18, 2016 at 2:26 PM, Sameer Kumar wrote: > > > On Thu, 19 May 2016, 2:07 a.m. shankha, wrote: >> >> The original table is : >> >> c1

Re: [GENERAL] Use of array_agg and array string on inner query

2016-05-18 Thread Sameer Kumar
On Thu, 19 May 2016, 2:07 a.m. shankha, wrote: > The original table is : > > c1 c2 c3 > 110 > 220 10 > 320 10 > > So c3 of row 3 and row 2 are equal to c2 of row 1. > > > The output I am looking for is : > c1 | array_to_string > +- >1 | 2,3 >2

Re: [GENERAL] Use of array_agg and array string on inner query

2016-05-18 Thread David G. Johnston
On Wed, May 18, 2016 at 1:07 PM, shankha wrote: > > /* 3. */ SELECT c1, c2, > ARRAY_TO_STRING(ARRAY_AGG((SELECT t3.c1 FROM s.t1 as t3 JOIN s.t1 > as t2 ON t3.c3 = t2.c2)), ',') > FROM s.t1 t1 > GROUP BY c1; > DROP SCHEMA s CASCADE; > ​The following adjustments should work:​

Re: [GENERAL] Use of array_agg and array string on inner query

2016-05-18 Thread shankha
The original table is : c1 c2 c3 110 220 10 320 10 So c3 of row 3 and row 2 are equal to c2 of row 1. The output I am looking for is : c1 | array_to_string +- 1 | 2,3 2 | 3 | (3 rows) How Can I modify this query : SELECT c1, c2,

Re: [GENERAL] Use of array_agg and array string on inner query

2016-05-18 Thread Sameer Kumar
On Thu, May 19, 2016 at 1:09 AM shankha wrote: > I have the following piece of code: > > DROP SCHEMA IF EXISTS s CASCADE; > CREATE SCHEMA s; > > CREATE TABLE "s"."t1" > ( > "c1" BigSerial PRIMARY KEY, > "c2" BigInt NOT NULL, > "c3" BigInt > ) > WITH

[GENERAL] Use of array_agg and array string on inner query

2016-05-18 Thread shankha
I have the following piece of code: DROP SCHEMA IF EXISTS s CASCADE; CREATE SCHEMA s; CREATE TABLE "s"."t1" ( "c1" BigSerial PRIMARY KEY, "c2" BigInt NOT NULL, "c3" BigInt ) WITH (OIDS=FALSE); INSERT INTO s.t1 (c2) VALUES (10); INSERT INTO