reform
reform copied to clipboard
UPSERT with single database statement
Several RDBMS support UPSERT (INSERT or UPDATE with a single statement):
We should add Upsert
method to reform. It should use a single RDBMS-specific statement. Behaviour could be RDBMS-specific too but well documented (see PostgreSQL wiki link for the good overview). It should not try to emulate it in unsupported RDBMS with several queries and/or transactions, it will return an error instead.
WIP branch that could be useful: https://github.com/go-reform/reform/tree/upsert.
@AlphaB What is your usecase?
@AlekSi I have a table with id
(pk), user_id
(reference to users table), entity_id
and some other columns. There is a unique index on user_id
and entity_id
columns and I want to be able to upsert records into this table by user_id
and entity_id
instead of making SELECT
and INSERT/UPDATE
. That's it.