Re: Unexpected behavior with CASE statement

From: Alvaro Herrera <alvherre(at)commandprompt(dot)com>
To: Jimmy Choi <yhjchoi(at)gmail(dot)com>
Cc: Rodrigo De León <rdeleonp(at)gmail(dot)com>, pgsql-general(at)postgresql(dot)org
Subject: Re: Unexpected behavior with CASE statement
Date: 2007-10-03 20:19:53
Message-ID: 20071003201953.GB24827@alvh.no-ip.org
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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)

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Tom Lane 2007-10-03 22:17:01 Re: PITR Recovery and out-of-sync indexes
Previous Message Jimmy Choi 2007-10-03 20:08:11 Re: Unexpected behavior with CASE statement