4 ms·
In ms sql you can do an update query, check the rowcount and if it's 0, then do an insert. That's how I got an improved query performance for syncing data.
by NicoJuicy 3y ago
In ms sql you can do an update query, check the rowcount and if it's 0, then do an insert.
That's how I got an improved query performance for syncing data.
- hot_gril 3y agoI think you need a unique index if you're doing something like this in MS-SQL, Postgres, or MySQL. Otherwise, the default isolation level won't prevent this data race: writer A: begin xact, update, see 0 rows updated writer B: begin xact, insert same thing, end xact writer A: insert, end xact One reason I use ON CONFLICT in Postgres is for explicitness. You're specifically telling the DBMS to upsert, and it'll throw an error if you don't have a unique index to support this.
- hot_gril 3y agoAlso mentioned above, ON CONFLICT DO UPDATE would be able to update the concurrent writer's row instead of throwing a uniqueness violation.