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

 

相关文章:

  • 2021-06-08
  • 2021-08-08
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-12-04
  • 2021-11-27
  • 2021-11-28
  • 2021-11-28
  • 2021-07-04
  • 2021-06-11
  • 2021-09-23
相关资源
相似解决方案