pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: darcy@druid.net
To: J.Fernando Moyano <txinete@wanadoo.es>
Cc: PgSQL-SQL <pgsql-sql@postgresql.org>
Subject: Re: Fwd: Re: sum(bool)?
Date: Sun, 25 Feb 2001 18:54:03 -0500 (EST)
Message-ID: <20010225235403.2F8E81A62@druid.net> (raw)
In-Reply-To: <01022522262800.01616@txino.mikasa.eh>

Thus spake J.Fernando Moyano
> El Viernes 23 Febrero 2001 16:22, escribiste:
> > i want to add up the "true" values of a comparison like
> >
> > sum(a>b)
> >
> > it just doesn't work like this
> >
> > any workaround?
> 
> I did exactly the same thing two months ago ....
> 
> I created this tiny function:
> 
> CREATE FUNCTION bool2int(bool) RETURNS integer
> 	AS 'select (case when $1=true then 1 else 0 end)'
> 	LANGUAGE 'sql';
> 
> 
> You can do:  sum(bool2int(a>b))
> 
> easy ??? ;-))

Almost as easy as "SELECT COUNT(*) FROM table WHERE a > b"

-- 
D'Arcy J.M. Cain <darcy@{druid|vex}.net>   |  Democracy is three wolves
http://www.druid.net/darcy/                |  and a sheep voting on
+1 416 425 1212     (DoD#0082)    (eNTP)   |  what's for dinner.



view thread (10+ messages)  latest in thread

Message-ID: <20010225235403.2F8E81A62@druid.net>
Permalink:  ../20010225235403.2F8E81A62@druid.net/
Also on:    postgresql.org/message-id/20010225235403.2F8E81A62@druid.net

 · 

reply

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 from your mail client; the link fills in
  the headers below: reply via email
  Some clients, webmail especially, drop In-Reply-To and References from
  a link, and the reply then starts a new thread: use the mbox below.

  To: pgsql-sql@postgresql.org
  Cc: darcy@druid.net, txinete@wanadoo.es
  Subject: Re: Fwd: Re: sum(bool)?
  In-Reply-To: <20010225235403.2F8E81A62@druid.net>
  References: <01022522262800.01616@txino.mikasa.eh> <20010225235403.2F8E81A62@druid.net>

* 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