Insert or update on a uniqueness collision.
Section: Insert, update, delete, and upsert
Upsert with ON CONFLICT
sql
sql
INSERT INTO users (email, display_name)
VALUES ('ava@example.com', 'Ava Martin')
ON CONFLICT(email) DO UPDATE SET display_name = excluded.display_name;Explanation
A high-value pattern for sync jobs, imports, and idempotent writes.
Learn the surrounding workflow
Compare similar commands or jump into common fixes when this command is part of a bigger troubleshooting path.
Related commands
Same sheet · prioritizing Insert, update, delete, and upsert