๐ŸŽ New User? Get 20% off your first purchase with code NEWUSER20 ยท โšก Instant download ยท ๐Ÿ”’ Secure checkout Register Now โ†’
Menu

Categories

Databases Intermediate

What is Upsert?

A database operation that inserts a new row if it does not exist, or updates the existing row if it does.

Upsert (update + insert) eliminates the need for separate check-then-insert-or-update logic. In PostgreSQL: INSERT INTO table (...) VALUES (...) ON CONFLICT (key) DO UPDATE SET column = EXCLUDED.column. MySQL uses INSERT ... ON DUPLICATE KEY UPDATE.

Upserts are atomic (no race conditions), simpler than alternatives, and efficient for sync operations, bulk imports, and idempotent data loading. The ON CONFLICT clause specifies which constraint determines whether to insert or update.

Related Terms

Query Optimization
The process of improving database query performance through indexing, query rewriting, and schema design techniques.
Normalization
The process of organizing database tables to reduce data redundancy and improve data integrity.
Partitioning
A technique of dividing large database tables into smaller, more manageable segments while maintaining a single logical table.
Graph Database
A database that uses graph structures with nodes, edges, and properties to store and query highly connected data.
Database Connection Pooling
A technique that maintains a cache of database connections for reuse, reducing the overhead of creating new connections.
Database Constraint
Rules enforced by the database to maintain data integrity, including NOT NULL, UNIQUE, CHECK, PRIMARY KEY, and FOREIGN KEY.
View All Databases Terms โ†’