Upsert in SQL: What is an Upsert, and When Should You Use One?
An upsert is a database operation that combines the functionality of an update and insert statement. It updates an existing row if a specified value already exists in a table, and inserts a new row if the specified value doesn't already exist. Upserts are useful for anyone who works with databases, but the term "upsert" might not appear in your DBMS's documentation as different RDBMS handle syntax for upserts differently. In MySQL, upserts can be achieved using INSERT … ON DUPLICATE KEY UPDATE, while PostgreSQL uses INSERT ON CONFLICT. CockroachDB has an UPSERT command and also supports upserts using INSERT ON CONFLICT.
Company
Cockroach Labs
Date published
Feb. 15, 2022
Author(s)
Charlie Custer
Word count
1257
Language
English
Hacker News points
None found.