In PostgreSQL, the ON CONFLICT we are using can have multiple column names. Is that multiple columns behave like AND or OR?
ON CONFLICT (name, mobile) DO UPDATE SET
address = EXCLUDED.address;
Does this mean, conflict occurs in
name AND mobile
or
name or mobile
2
Answers
According to the documentation you need SELECT/UPDATE privilege to the columns specified.
As long as either of the columns specified is in
conflict_target
it will performconflict_action
.An
on conflict(col1,col2)
establishes and AND condition on the columns, all must match values from an existing row. Further you cannot just name the any columns you must first defineunique constraint
on the specific columns. Finally only oneon conflict()
condition can be specified in a given DML statement. See demo as duplicated below:Notice that the conflict_action is executed only in statement set #4 where both columns match.