Quantcast

Horizontal aggregation?

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Horizontal aggregation?

hamann.w


Hi,

I am looking for a feature that would select from a table with
k1  a
k1  b
k1  c
k2  a
k3  b
k3  c
something like
k1  a b c
k2  a
k3  b c
(Just all elements next to each other, with a space in between)
or perhaps an array output
k1  {a,b,c]
k2  {a}
k3  {b,c}

If such an operator exists, would there be a "remove duplicates" option?

Regards
Wolfgang Hamann


--
Sent via pgsql-general mailing list ([hidden email])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Horizontal aggregation?

Abel Camarillo
On Sat, Apr 14, 2012 at 1:22 AM,  <[hidden email]> wrote:

>
>
> Hi,
>
> I am looking for a feature that would select from a table with
> k1  a
> k1  b
> k1  c
> k2  a
> k3  b
> k3  c
> something like
> k1  a b c
> k2  a
> k3  b c
> (Just all elements next to each other, with a space in between)
> or perhaps an array output
> k1  {a,b,c]
> k2  {a}
> k3  {b,c}
>
> If such an operator exists, would there be a "remove duplicates" option?
>
> Regards
> Wolfgang Hamann
>
>
> --
> Sent via pgsql-general mailing list ([hidden email])
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-general

select k, array_agg(distinct val ) from t;

See the docs: http://www.postgresql.org/docs/9.1/static/sql-expressions.html#SYNTAX-AGGREGATES

--
Sent via pgsql-general mailing list ([hidden email])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Horizontal aggregation?

Abel Camarillo
On Sat, Apr 14, 2012 at 1:28 AM, Abel Abraham Camarillo Ojeda
<[hidden email]> wrote:

> On Sat, Apr 14, 2012 at 1:22 AM,  <[hidden email]> wrote:
>>
>>
>> Hi,
>>
>> I am looking for a feature that would select from a table with
>> k1  a
>> k1  b
>> k1  c
>> k2  a
>> k3  b
>> k3  c
>> something like
>> k1  a b c
>> k2  a
>> k3  b c
>> (Just all elements next to each other, with a space in between)
>> or perhaps an array output
>> k1  {a,b,c]
>> k2  {a}
>> k3  {b,c}
>>
>> If such an operator exists, would there be a "remove duplicates" option?
>>
>> Regards
>> Wolfgang Hamann
>>
>>
>> --
>> Sent via pgsql-general mailing list ([hidden email])
>> To make changes to your subscription:
>> http://www.postgresql.org/mailpref/pgsql-general
>
> select k, array_agg(distinct val ) from t;
>
> See the docs: http://www.postgresql.org/docs/9.1/static/sql-expressions.html#SYNTAX-AGGREGATES

obviously I forgot the group by:


select k, array_agg(distinct val ) from t group by k;

--
Sent via pgsql-general mailing list ([hidden email])
To make changes to your subscription:
http://www.postgresql.org/mailpref/pgsql-general
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Horizontal aggregation?

hamann.w


>> >>
>> >> Hi,
>> >>
>> >> I am looking for a feature that would select from a table with
>> >>
>> >> If such an operator exists, would there be a "remove duplicates" option?
>> >>
>> >> Regards
>> >> Wolfgang Hamann
>> >>
>> >
>> > select k, array_agg(distinct val ) from t;
>> >
>> > See the docs: http://www.postgresql.org/docs/9.1/static/sql-expressions.h=
>> tml#SYNTAX-AGGREGATES
>>
>> obviously I forgot the group by:
>>
>>
>> select k, array_agg(distinct val ) from t group by k;

Hi Abel,

thanks a lot.

Regards
Wolfgang Hamann


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

Loading...