how to replace bitand function and decode oracle function in postgres sql?
select decode(bitand(p.privilege, 2), 2, 'true', 'false') as is_approver
from person p;
tried below sql
select case ((p.privilege & 2 = 2))::int when 2 then 'true' else 'false' end as is_approver
from person p;
2
Answers
That should be
The expression
p.privilege & 2 = 2
will return aboolean
value. If you can work with them inside your application, then all you need is:If you really want string values for
true
andfalse
, then you need to test the boolean value. Your expression is comparing the boolean value to an integer