Reputation: 25
I want to convert the decode function from oracle to postgres command. example oracle command: select decode(p.statusgeometry,1,'pass','fail') as status
please help & guidance
Upvotes: 1
Views: 3903
Reputation: 19613
The decode
equivalent is CASE
:
WITH p (statusgeometry) AS (VALUES (1),(2))
SELECT
CASE statusgeometry
WHEN 1 THEN 'pass'
WHEN 2 THEN 'fail'
END,
-- The following syntax is useful in case you need to do "something"
-- with the columns depending on the condition, e.g lower(), upper(), etc..
CASE
WHEN statusgeometry = 1 THEN 'pass'
WHEN statusgeometry = 2 THEN 'fail'
END
FROM p;
case | case
------+------
pass | pass
fail | fail
(2 rows)
Upvotes: 2