3 ms·
Does every application (and process) using your database automatically know what's in every table at every moment? That's highly unlikely, so you still have to
by manigandham 6y ago
Does every application (and process) using your database automatically know what's in every table at every moment? That's highly unlikely, so you still have to do queries to find out. And then what would you do if the tuple was or wasn't in there already?
Whatever your answer is, UPSERT just combines that into a single more efficient statement. There's no new logic, just a better expression of it.
If you want examples: 1) analytics with `key(id,timestamp)` to avoid manually creating new rows as time goes on. 2) OLTP updates where we only want the latest data. 3) new data from multiple sources concurrently and we want the last write. 4) duplicate data and we want a single copy for each key.