PostgreSQL · Command
ON CONFLICT
ON CONFLICT handles a unique or exclusion conflict during INSERT. It can skip the row or update the existing row, making an atomic insert-or-update operation.
Last updated
Syntax
[ WITH [ RECURSIVE ] with_query [, ...] ] INSERT INTO table_name [ AS alias ] [ ( column_name [, ...] ) ] [ OVERRIDING { SYSTEM | USER } VALUE ] { DEFAULT VALUES | VALUES ( { expression | DEFAULT } [, ...] ) [, ...] | query } [ ON CONFLICT [ conflict_target ] conflict_action ] [ RETURNING [ WITH ( { OLD | NEW } AS output_alias [, ...] ) ] { * | output_expression [ [ AS ] output_name ] } [, ...] ]In-depth API docs are only for subscribers: parameters, examples, common mistakes and interview practice.
SubscribeRelated
INSERTON CONFLICT DO NOTHINGON CONFLICT DO UPDATERETURNINGMERGEunique index inferenceEXCLUDEDRead Committed Isolation Level