Re: Problem With Case Statement and Aggregate Functions - Mailing list pgsql-bugs

From Tom Lane
Subject Re: Problem With Case Statement and Aggregate Functions
Date
Msg-id 17423.1178888481@sss.pgh.pa.us
Whole thread Raw
In response to Problem With Case Statement and Aggregate Functions  (Andrew Shea <andrew@octahedron.com.au>)
List pgsql-bugs
Andrew Shea <andrew@octahedron.com.au> writes:
> However the following code doesn't work even though it is very similar
> to the first query (that is, and aggregate function within a case
> statement):

> select (SELECT CASE WHEN (1=2) THEN 0 ELSE COUNT(*) END) from (
          ^^^^^^
>  select 1 as count union select 2 union select 3
> ) as "temp";

Lose the underlined SELECT and it will behave the way you expect.
As-is the COUNT is an aggregate of that sub-select, not of the topmost
select.  To be considered an aggregate of the topmost select it has
to reference a variable of that query level.

            regards, tom lane

pgsql-bugs by date:

Previous
From: "Nilay Ceter"
Date:
Subject: BUG #3268: pgpass.conf error
Next
From: "Bojan Jovanovic"
Date:
Subject: BUG #3269: PSQL does not display error output