postgresql将字段为空的值替换为指定值

  1. null 表示缺失的值, '' " "表示空值
    null 参与的表达式运算都返回null
    使用is null 判断是null
    is not null 判断非null
  2. nullif(value1, value2) 如果value1 == value2 返回null
  3. coalesce(arg1, arg2, ...) 返回第一个 不为null的值

所以可以使用如下语句,实现将table中filed为空的记录替换为指定值

update table set filed = COALESCE(NULLIF(trim("filed"), ''), 'value')

COALESCE(NULLIF(to_char(T1.online_tm, 'yyyy-MM-dd HH24:MI:SS'), '1900-01-01 00:00:00'), ' ')

猜你喜欢

转载自blog.csdn.net/HUXU981598436/article/details/83114468