SoFunction
Updated on 2025-03-10

Postgresql implementation replaces the value with the empty field with the specified value

1. null indicates the missing value, '' " " indicates the empty value

null all participating expression operations return null

Use is null to determine if it is null

is not null judge non-null

2. nullif(value1, value2) If value1 == value2 returns null

3. coalesce(arg1, arg2, ...) Returns the first value that is not null

Therefore, you can use the following statement to replace the record with empty filed in the table with the specified value

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

Supplement: Postgrepsql determines that the field is empty and returns 0

I won't say much nonsense, let's just read the code~

select *,COALESCE(p_id,0) is_pid from sys_unit where 1=1

The above is personal experience. I hope you can give you a reference and I hope you can support me more. If there are any mistakes or no complete considerations, I would like to give you advice.