Difference between UPSERT and MERGE?
10
votes
2
answers
19043
views
From the PostgreSQL wiki,
>
MERGE
is typically used to merge two tables, and was introduced in the 2003 SQL standard. The REPLACE
statement (a MySQL extension) or *UPSERT* sequence attempts an UPDATE
, or on failure, INSERT
. This is similar to UPDATE
, then for unmatched rows, INSERT
. Whether concurrent access allows modifications which could cause row loss is implementation independent.
Further PostgreSQL's [INSERT ... ON CONFLICT DO NOTHING/UPDATE
](https://wiki.postgresql.org/wiki/What%27s_new_in_PostgreSQL_9.5#INSERT_..._ON_CONFLICT_DO_NOTHING.2FUPDATE_.28.22UPSERT.22.29) is marketed as *UPSERT* and was added in 9.5
What then is MERGE
? And how does it fit into the mix?
Asked by Evan Carroll
(65502 rep)
Apr 7, 2018, 09:12 AM
Last activity: Mar 5, 2025, 01:47 PM
Last activity: Mar 5, 2025, 01:47 PM