UPSERT என்றால் "செருக, அல்லது ஏற்கனவே இருந்தால் புதுப்பிக்க." PostgreSQL இதை INSERT ... ON CONFLICT மூலம் செயல்படுத்துகிறது — ஒரு வரிசையை செருக, ஆனால் அது ஒரு unique கட்டுப்பாட்டை மீறினால், மாறாக বதிலான வரிசையை புதுப்பிக்க (அல்லது எதுவும் செய்யாமல் விட்டுவிட). இது "செருக-அல்லது-புதுப்பிக்க" என்ற பொதுவான தேவையை atomically கையாளுகிறது.
UPSERT தீர்க்கும் சிக்கல்
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)
