PostgreSQL · Command
MERGE
MERGE conditionally inserts, updates, deletes, or skips rows in a target table using source data. It joins source and target rows, then runs the first matching WHEN action for each candidate row.
Last updated
Syntax
[ WITH with_query [, ...] ] MERGE INTO [ ONLY ] target_table_name [ * ] [ [ AS ] target_alias ] USING data_source ON join_condition when_clause [...] [ 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
INSERTUPDATEDELETERETURNINGmerge_action()CREATE POLICYALTER TABLE ... ENABLE ROW LEVEL SECURITY