Aggregate from CASE WHEN... - Mailing list pgsql-novice

From Ioannis Anagnostopoulos
Subject Aggregate from CASE WHEN...
Date
Msg-id 4FF8E688.7060301@anatec.com
Whole thread Raw
Responses Re: Aggregate from CASE WHEN...  (Tom Lane <tgl@sss.pgh.pa.us>)
List pgsql-novice
Hello,

I am trying to aggregate some data but conditionally as follows:

SELECT
         feed_all_y2012m01.array_accum(message_copies.msg_id) as
messages_array,
         uniq(feed_all_y2012m01.array_accum(obj_mmsi)) as mmsi_array,
         CASE WHEN msg_type BETWEEN  1 and  3 THEN
feed_all_y2012m01.array_accum(message_copies.msg_id) END as msgA,
         CASE WHEN msg_type = 18 THEN
feed_all_y2012m01.array_accum(message_copies.msg_id) END as msgB_std,
         CASE WHEN msg_type = 19 THEN
feed_all_y2012m01.array_accum(message_copies.msg_id) END as msgB_ext,
         CASE WHEN obj_type = 'SHIP_TYPE_A' THEN
uniq(feed_all_y2012m01.array_accum(obj_mmsi)) END as mmsi_type_a_array,
         CASE WHEN obj_type = 'SHIP_TYPE_B' THEN
uniq(feed_all_y2012m01.array_accum(obj_mmsi)) END as mmsi_type_b_array,
         .......

The logic breaks where PGSQL forces me(?) to group by msg_type and
obj_type while I was hoping that msg_type and obj_type could just be
considered as the variables that the conditions would be checked against.
Neither I want to use some form of aggregation on these two fields. Is
there any way that I can achieve something like this?

Thank you
Yiannis

pgsql-novice by date:

Previous
From: Gurjeet Singh
Date:
Subject: Re: Recheck condition...
Next
From: Tom Lane
Date:
Subject: Re: Aggregate from CASE WHEN...