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.使用...联合;使...合并

 

posted @ 2017-05-28 12:15  庚武  Views(8561)  Comments(0Edit  收藏  举报