pg.ddx.io  pgsql-sql@postgresql.org mailing list archive  
help / color / mirror / Atom feed
From: J.Fernando Moyano <txinete@wanadoo.es>
To: PgSQL-SQL <pgsql-sql@postgresql.org>
Subject: Fwd: Re: sum(bool)?
Date: Sun, 25 Feb 2001 22:26:28 +0100
Message-ID: <01022522262800.01616@txino.mikasa.eh> (raw)


El Viernes 23 Febrero 2001 16:22, escribiste:
> hi there,
>
> i want to add up the "true" values of a comparison like
>
> sum(a>b)
>
> it just doesn't work like this
>
> any workaround?
>
> it is postgresql 7.0 under linux
>
> thanks
>
> olaf

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 ??? ;-))


--
Fernando Moyano

Frase del día:
--------------
El medico me prohibio beber wiski, ahora lo congelo y me lo como!

(*) SymeX ==> http://symex.lantik.com
(*) WDBIL ==> http://wdbil.sourceforge.net
(*) Informate sobre LINUX en http://www.linux.org




view thread (10+ messages)  latest in thread

Message-ID: <01022522262800.01616@txino.mikasa.eh>
Permalink:  ../01022522262800.01616@txino.mikasa.eh/
Also on:    postgresql.org/message-id/01022522262800.01616@txino.mikasa.eh

 · 

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: txinete@wanadoo.es
  Subject: Re: Fwd: Re: sum(bool)?
  In-Reply-To: <01022522262800.01616@txino.mikasa.eh>
  References: <01022522262800.01616@txino.mikasa.eh>

* 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