SQL · Writing data

upsert

Inserts or updates when a unique constraint is violated. PostgreSQL and SQLite support ON CONFLICT.

Syntax
insert … on conflict … do update

Example

Open in the lab

More in this group

delete insert insert from select insert returning merge truncate update update from

Learn this in the course

Reference pages are the quick answer. The course explains the why, shows the full example and ends with a challenge.

Open the course