Re: Problem With Case Statement and Aggregate Functions

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: Problem With Case Statement and Aggregate Functions
Дата
Msg-id 17423.1178888481@sss.pgh.pa.us
обсуждение исходный текст
Ответ на Problem With Case Statement and Aggregate Functions  (Andrew Shea <andrew@octahedron.com.au>)
Список 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 по дате отправления:

Предыдущее
От: "Nilay Ceter"
Дата:
Сообщение: BUG #3268: pgpass.conf error
Следующее
От: "Bojan Jovanovic"
Дата:
Сообщение: BUG #3269: PSQL does not display error output