Skip site navigation (1) Skip section navigation (2)

Re: One query for two information...

From: "Moray McConnachie" <moray(dot)mcconnachie(at)computing-services(dot)oxford(dot)ac(dot)uk>
To: "Ed" <dziablo(at)lords(dot)com>, "pgsql sql" <pgsql-sql(at)postgresql(dot)org>
Subject: Re: One query for two information...
Date: 2000-04-18 15:31:27
Message-ID: 00e601bfa94b$29833810$ (view raw, whole thread or download thread mbox)
Lists: pgsql-sql
create function boolint (bool) RETURNS int4 AS
'SELECT CASE WHEN $1=''false'' THEN 0 ELSE 1 END;'
SELECT SUM(boolint(fieldname)) FROM tablename;

note double single quote in 2nd line.
----- Original Message -----
From: "Ed" <dziablo(at)lords(dot)com>
To: "pgsql sql" <pgsql-sql(at)postgresql(dot)org>
Sent: Tuesday, April 18, 2000 3:26 PM
Subject: [SQL] One query for two information...


I have a table containing only a bool filed.  I would like to know how many
records there is an on many ar true.

Is there something I could do to get both answer in only one query...   like

select count(*), sum(bool_col) from tablename

but there is no sum(bool) function that would add 1 if it's true and 0 if
it's false... ;(

Any idea?

Frédéric Boucher

In response to

pgsql-sql by date

Next:From: Frank BaxDate: 2000-04-18 16:18:50
Subject: psql & java
Previous:From: Allan KellyDate: 2000-04-18 15:16:29
Subject: Mystery: functions are slow with group by, but...

Privacy Policy | About PostgreSQL
Copyright © 1996-2017 The PostgreSQL Global Development Group