reform icon indicating copy to clipboard operation
reform copied to clipboard

UPSERT with single database statement

Open AlekSi opened this issue 8 years ago • 2 comments

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.

AlekSi avatar May 30 '16 20:05 AlekSi

@AlphaB What is your usecase?

AlekSi avatar Apr 30 '17 03:04 AlekSi

@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.

AlphaB avatar May 02 '17 12:05 AlphaB