在Oracle中解码转换为Postgres
我想将DECODE函数从Oracle转换为Postgres命令。 示例Oracle命令:选择DECODE(p.statusgeometry1,‘PASS’,‘FAIL’)作为状态
请帮助和指导
解决方案
decode
等效项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)
相关文章