Uma sequência será incrementada sempre que uma inserção for tentada, independentemente de seu sucesso. Uma simples
update (como no seu exemplo) não irá incrementá-lo, mas um insert on conflict update vai desde o insert é tentado antes da update . Uma solução é alterar o
id para bigint . Outra é não usar uma sequência e gerenciá-la você mesmo. E outra é fazer um upsert manual:with s as (
select id
from notifications
where title = 'something'
), i as (
insert into notifications (title, description)
select 'something', 'whatever'
where not exists (select 1 from s)
)
update notifications
set title = 'something else'
where id = (select id from s)
Isso supõe
title é único.