From: Tom Lane <tgl@sss.pgh.pa.us>
To: guenther@laokoon.IN-Berlin.DE
Cc: pgsql-sql@hub.org
Subject: Re: [SQL] sum-function
Date: Sat, 23 Oct 1999 00:55:35 -0400
Message-ID: <799.940654535@sss.pgh.pa.us> (raw)
In-Reply-To: <199910222334.BAA11750@laokoon.bug.net>
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Reply to all the recipients using the --to and --cc options:
reply via email
To: pgsql-sql@postgresql.org
Cc: tgl@sss.pgh.pa.us, guenther@laokoon.IN-Berlin.DE, pgsql-sql@hub.org
Subject: Re: [SQL] sum-function
In-Reply-To: <799.940654535@sss.pgh.pa.us>
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
This inbox is served by DDX for PostgreSQL; see mirroring instructions
for how to clone and mirror all data and code used for this inbox