UPSERT "ekle, ya da zaten varsa güncelle" anlamına gelir. PostgreSQL bunu INSERT ... ON CONFLICT ile uygular — bir satır ekle, ancak bu benzersiz bir kısıtlamayı ihlal ederse, bunun yerine mevcut satırı güncelle (ya da hiçbir şey yapma). Ortak "ekle-veya-güncelle" ihtiyacını atomik şekilde işler.
UPSERT'ün çözdüğü sorun
You want to insert a row, but it might already exist (by a unique key):
❌ a plain INSERT fails with a unique-violation error if it exists
❌ check-then-insert (SELECT, then INSERT or UPDATE) has a RACE CONDITION
(another transaction could insert between your check and insert)
→ ON CONFLICT does it atomically in ONE statement (no race condition)
