Re: Unexpected behavior with CASE statement - Mailing list pgsql-general

From Alvaro Herrera
Subject Re: Unexpected behavior with CASE statement
Date
Msg-id 20071003201953.GB24827@alvh.no-ip.org
Whole thread Raw
In response to Re: Unexpected behavior with CASE statement  ("Jimmy Choi" <yhjchoi@gmail.com>)
List pgsql-general
Jimmy Choi escribió:
> This will work for this particular example. But what if my case
> statement is more complicated than that? Example:
>
> select
>    metric_type,
>    case metric_type
>       when 0 then
>          sum (1 / val)
>       when 1 then
>          sum (val)
>       when 2 then
>          max (val)
>       when 3 then
>          min (val)
>    end as result
> from metrics
> group by metric_type

This doesn't make sense.  Use separate output columns for the different
aggregates.

--
Alvaro Herrera                  http://www.amazon.com/gp/registry/5ZYLFMCVHXC
"Crear es tan difícil como ser libre" (Elsa Triolet)

pgsql-general by date:

Previous
From: "Jimmy Choi"
Date:
Subject: Re: Unexpected behavior with CASE statement
Next
From: Tom Lane
Date:
Subject: Re: PITR Recovery and out-of-sync indexes