Decode equivalent in postgres

前端 未结 3 700
一整个雨季
一整个雨季 2021-02-13 02:36

There is no equivalent to the Oracle\'s DECODE()\'Function InPostgres`. Is there anyone who wrote decode as a Function?

3条回答
  •  情歌与酒
    2021-02-13 03:00

    You can combine NULLIF with COALESCE:

    SELECT COALESCE(NULLIF(value, 0), newValue) FROM table;

    Font: Coalesce for zero instead of null

提交回复
热议问题