1. 程式人生 > >postgresql將欄位為空的值替換為指定值

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'), ' ')