1

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

1
  • select (case p.statusgeometry when 1 then 'pass' else 'fail' end) as status Commented Jul 23, 2021 at 9:02

1 Answer 1

2

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)
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.