How about this?
CREATE OR REPLACE FUNCTION equal_int_bool(x int, y bool)
RETURNS BOOLEAN AS $$
begin
return x = y::int;
end;
$$ LANGUAGE PLPGSQL IMMUTABLE STRICT;
CREATE OPERATOR = (
leftarg = INTEGER,
rightarg = BOOLEAN,
procedure = equal_int_bool);
CREATE OR REPLACE FUNCTION equal_bool_int(x bool, y int)
RETURNS BOOLEAN AS $$
begin
return x::int = y;
end;
$$ LANGUAGE PLPGSQL IMMUTABLE STRICT;
CREATE OPERATOR = (
leftarg = BOOLEAN,
rightarg = INTEGER,
procedure = equal_bool_int);
Example truths:
> select 0=false a, false=0 b, 1=true c, true=1 d;
a | b | c | d
---+---+---+---
t | t | t | t
Expect false for all other comparisons:
> select 1=false a, 0=true b, 2=true c, -1=true d, true=-1 e;
a | b | c | d | e
---+---+---+---+---
f | f | f | f | f
Note: I'm a relative Postgresql novice, and am not recommending you create tons of random implicit conversions in your database, but thought it interesting that this was possible. Feel free to warn of dangers.
P.S. I'm deliberating whether a better semantic is 0=false, non-zero=true. Depends on your use case.