PostgreSQL coalesce function data conversion method

Time:2022-4-28

Oracle’s NVL (col, 0) is to judge that if the col field is empty, it is assigned 0, and the function in the same PostgreSQL is coalesce. The usage is the same


  SELECT coalesce(collect_result,value) as collect_result 
   FROM collect 

If the queried field in the database is collect_ If result is empty, assign value to collect_ result。

Supplement: when the PostgreSQL coalesce field is empty, a fixed value is assigned, which is equivalent to the NVL of Oracle

Assign a fixed value when the field is empty


select coalesce(column_name,0) from table_name;

The above is my personal experience. I hope I can give you a reference, and I hope you can support developpaer. If there are mistakes or not fully considered, please don’t hesitate to comment.