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.使用...聯合;使...合並