Re: add, subtract bool type - Mailing list pgsql-general

From Peter Eisentraut
Subject Re: add, subtract bool type
Date
Msg-id Pine.LNX.4.30.0108221711230.679-100000@peter.localdomain
Whole thread Raw
In response to add, subtract bool type  (Jeff Davis <list-pgsql-general@dynworks.com>)
List pgsql-general
Jeff Davis writes:

> I made some simple functions that create the operators + and - for any
> combination of int4's and bool's.
>
> The reasoning that propted this operator was that I wanted to use the
> following syntax in a query:
> SELECT *,((col_a == 'foo') + (col_b == 'bar')) as relevance WHERE
> relevance > 0;

You could also try

case when col_a = 'foo' then 1 else 0 end + case when col_b = 'bar' then 1
else 0 end

which is the usual way to "cast" booleans.

--
Peter Eisentraut   peter_e@gmx.net   http://funkturm.homeip.net/~peter


pgsql-general by date:

Previous
From: "Paul C."
Date:
Subject: FTI is really really slow; what am I doing wrong?
Next
From: "Mitch Vincent"
Date:
Subject: Re: FTI is really really slow; what am I doing wrong?