๐ŸŽ 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

Connection String
A formatted string containing all parameters needed to establish a connection to a database server.
SQL
Structured Query Language โ€” the standard language for managing and querying data in relational databases.
EXPLAIN Plan
A database command that shows how the query planner will execute a SQL query, revealing join methods, scan types, and estimated costs.
Cursor
A database object that enables row-by-row processing of query results, useful for operations that cannot be done in bulk.
Database Backup
The process of creating copies of database data to protect against data loss from failures, corruption, or human error.
JSONB
PostgreSQL's binary JSON data type that stores JSON documents with indexing, querying, and manipulation capabilities.
View All Databases Terms โ†’