pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: Pavel Stehule <pavel.stehule@gmail.com>
To: emilu@encs.concordia.ca
Cc: pgsql-sql@postgresql.org
Subject: Re: "select c1, method(c2) group by c1" returns all values of c2 for c1
Date: Tue, 8 Feb 2011 20:43:19 +0100
Message-ID: <AANLkTimZi_ouNUm8EOyL8RmL5Op-TQwfTwJ4_4NQspFF@mail.gmail.com> (raw)
In-Reply-To: <4D519B0A.9040708@encs.concordia.ca>
References: <4D519B0A.9040708@encs.concordia.ca>

Hello

you can use a string%agg function if you have a 9.0. On older version
there is a array_agg function

select c1, array_to_string(array_agg(c2),',') from T1 group by c1

regards

Pavel Stehule

2011/2/8 Emi Lu <emilu@encs.concordia.ca>:
> Good afternoon,
>
> Is there a method to retrieve the following results:
>
> T1(c1 int, c2 varchar(128) )
> ---------------------------------
>
>
> (1, val1);
> (1, val2);
> (1, val3);
> (2, val1);
> (3, val5);
> (3, val6);
>
> select c1, method(c2)
> group by c1
>
> returns:
> ============
> 1,   "val1, val2, val3"
> 2,   "val1"
> 3,   "val5, val6"
>
>
> Thanks a lot!
>
> --
> Lu Ying
>
> --
> Sent via pgsql-sql mailing list (pgsql-sql@postgresql.org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-sql
>



view thread (6+ messages)  latest in thread

Message-ID: <AANLkTimZi_ouNUm8EOyL8RmL5Op-TQwfTwJ4_4NQspFF@mail.gmail.com>
Permalink:  ../AANLkTimZi_ouNUm8EOyL8RmL5Op-TQwfTwJ4_4NQspFF@mail.gmail.com/
Also on:    postgresql.org/message-id/AANLkTimZi_ouNUm8EOyL8RmL5Op-TQwfTwJ4_4NQspFF@mail.gmail.com

 · 

reply

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Reply to all the recipients using the --to and --cc options:
  reply via email

  To: pgsql-sql@postgresql.org
  Cc: pavel.stehule@gmail.com, emilu@encs.concordia.ca
  Subject: Re: "select c1, method(c2) group by c1" returns all values of c2 for c1
  In-Reply-To: <AANLkTimZi_ouNUm8EOyL8RmL5Op-TQwfTwJ4_4NQspFF@mail.gmail.com>

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox