PostgreSQL判断是否为空coalesce

coalesce(expr1,expr2,expr3...)

直到找到一个非null值返回,右边的表达式则不参与运算;若所有为null,返回null.

eg:判断json是否包含某属性,若无,则取默认值。

testdb=# select val * 2 from (select id, coalesce(cast(data->>'age' as decimal) , id ) val from testjson2)t;

testdb=# select val * 2 from (select id, coalesce(cast(data->>'age' as decimal) ,null, id ) val from testjson2)t;

coalesce

vi.合并;结合;联合

vt.使用...联合;使...合并

原文地址:https://www.cnblogs.com/wucg/p/6915440.html