From: | darcy(at)druid(dot)net (D'Arcy J(dot)M(dot) Cain) |
---|---|
To: | "J(dot)Fernando Moyano" <txinete(at)wanadoo(dot)es> |
Cc: | PgSQL-SQL <pgsql-sql(at)postgresql(dot)org> |
Subject: | Re: Fwd: Re: sum(bool)? |
Date: | 2001-02-25 23:54:03 |
Message-ID: | 20010225235403.2F8E81A62@druid.net |
Views: | Raw Message | Whole Thread | Download mbox | Resend email |
Thread: | |
Lists: | pgsql-sql |
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(at){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.
From | Date | Subject | |
---|---|---|---|
Next Message | Ken Kline | 2001-02-26 02:32:06 | conversion |
Previous Message | J.Fernando Moyano | 2001-02-25 21:26:28 | Fwd: Re: sum(bool)? |