3 ms·
If you are that concerned, put "begin;" before your command, check that the updated/inserted number is reasonable, and then either do a commit or a rollback. Th
by saurik 10y ago
If you are that concerned, put "begin;" before your command, check that the updated/inserted number is reasonable, and then either do a commit or a rollback. That way you also didn't screw up N+1 totally random rows. You can even put a returning clause on the update to see which rows you were affecting.
- piaste 10y agoOr if you can't afford to lock the table in the process, before you run UPDATE {foo} WHERE {bar} you back up the relevant rows into a temporary table with SELECT * INTO foo_backup WHERE {bar}.
- saurik 10y agoNone of this should cause a table lock: at best you will just lock the affected rows and at worst you will end up with a predicate lock on the where clause.
- scardine 10y agoPostgres uses MVCC (Multiversion concurrency control), it solves concurrency without locking everything you touch.