Reputation: 378
I am trying to update a field with a null value when the select doesn't return values.
Eg:
UPDATE table SET title = COALESCE(a.title, NULL)
FROM (
SELECT '1' AS title WHERE 0 = 1) a
WHERE id = 1
So, the select that the update is updating from is not returning any rows, the title should get null value.
Upvotes: 0
Views: 51
Reputation: 36107
Use:
update t set title = (SELECT '1' AS title WHERE 0 = 1)
where id = 1
Upvotes: 1