Re: [SQL] sum-function

Поиск
Список
Период
Сортировка
От Tom Lane
Тема Re: [SQL] sum-function
Дата
Msg-id 799.940654535@sss.pgh.pa.us
обсуждение исходный текст
Ответ на sum-function  (guenther@laokoon.IN-Berlin.DE (Christian Guenther))
Список pgsql-sql
guenther@laokoon.IN-Berlin.DE (Christian Guenther) writes:
> udmsearch=> select sum( dict.word = 'mysql') from dict\g
> ERROR:  Unable to select an aggregate function sum(bool)
> What does the ERROR mean.

The '=' operator produces a boolean (true/false) result, but
sum() wants a numeric input.  Postgres is a strongly-typed
system, so it doesn't think booleans are interchangeable
with numerics.

It's been suggested several times that Postgres should
provide a standard conversion function that converts
boolean values to 0/1 numeric values, but no one's gotten
around to making one.  In the meantime you could get the
result that I think you want with something like

select sum(case when dict.word = 'mysql' then 1 else 0 end) ...
        regards, tom lane


В списке pgsql-sql по дате отправления:

Предыдущее
От: guenther@laokoon.IN-Berlin.DE (Christian Guenther)
Дата:
Сообщение: sum-function
Следующее
От: "Albert REINER"
Дата:
Сообщение: Can VACUUM, but cannot do VACUUM ANALYZE