2 ms·
Now if only there was some syntax shorthand for "just take everything from this now conflicting INSERT and discard what's already there". Like SQLite's "INSERT
by pilif 11y ago
Now if only there was some syntax shorthand for "just take everything from this now conflicting INSERT and discard what's already there".
Like SQLite's "INSERT OR REPLACE".
Aside of the transactional benefits that upsert has, it's also convenient in that you don't have to update and then insert, saving a lot of typing in cases where you're not relying on an ORM and still have to work with bulk data where you really don't care about local changes (because there were none).
The syntax for this is a bit inconvenient right now.
- mbreese 11y agoThe syntax looks inconvenient, but I like it. If you have a conflict, you might not want to just update everything, but only a subset of the fields. With this syntax (verbose as it is), you have the option of explicitly stating what you want to happen in the event of a conflict with no ambiguity. Perhaps there is a place for some shorthand like ON CONFLICT SET *=*. But aside from that, for a RDBMS like Postgres, I'd opt for explicit over implicit.
- tracker1 11y agoOne would think you would just need a list of fields... ON CONFLICT SET colA,colB,colC As to the gp, you don't want to update the "CREATED" field on an upsert.