Re: add, subtract bool type

From: Peter Eisentraut <peter_e(at)gmx(dot)net>
To: Jeff Davis <list-pgsql-general(at)dynworks(dot)com>
Cc: <pgsql-general(at)postgresql(dot)org>
Subject: Re: add, subtract bool type
Date: 2001-08-22 15:12:23
Message-ID: Pine.LNX.4.30.0108221711230.679-100000@peter.localdomain
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: 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(at)gmx(dot)net http://funkturm.homeip.net/~peter

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Andrew Gould 2001-08-22 15:17:21 During dump: function not found
Previous Message Lamar Owen 2001-08-22 15:10:47 Re: New RPMS ?