Re: ARRAY_AGG and COUNT - Mailing list pgsql-sql

From bricklen
Subject Re: ARRAY_AGG and COUNT
Date
Msg-id AANLkTinVgQKaF98eUrDMiC8wz=UX3Bukc-L_D4X3-+hM@mail.gmail.com
Whole thread Raw
In response to Re: ARRAY_AGG and COUNT  (Andreas Forø Tollefsen <andreasft@gmail.com>)
List pgsql-sql
On Thu, Feb 17, 2011 at 12:11 PM, Andreas Forø Tollefsen
<andreasft@gmail.com> wrote:
> Great. Thanks. Do you have a suggestion on how to ignore the group id's with
> 0 as value?
> I dont want these to be counted.

You can probably select your values in a subquery and filter out the 0
value results in the WHERE clause, then apply your existing query
(with distinct array_agg) to the outer query.
Or another way would be to use a CASE statement to skip the 0 values.
eg.
array_to_string(array_agg(distinct (case when g1id <> 0 then g1id end)
),';') ...

The array_to_string transformation should trim out the NULLs from the
CASE statement.


pgsql-sql by date:

Previous
From: Andreas Forø Tollefsen
Date:
Subject: Re: ARRAY_AGG and COUNT
Next
From: Sivannarayanreddy
Date:
Subject: Re: Function compile error