this post was submitted on 06 Nov 2023
1314 points (98.7% liked)
Programmer Humor
32495 readers
546 users here now
Post funny things about programming here! (Or just rant about your favourite programming language.)
Rules:
- Posts must be relevant to programming, programmers, or computer science.
- No NSFW content.
- Jokes must be in good taste. No hate speech, bigotry, etc.
founded 5 years ago
MODERATORS
you are viewing a single comment's thread
view the rest of the comments
view the rest of the comments
Transactions are the safe way of doing it.
You can also return * to see the changes, or add specific fields.
Like for example:
Begin; Update users Set first_name='John' Where first_name='john' Returning *;
Then your Rollback; Or Commit;
So you'd see all rows you just updated. You can get fancy and do a self join and see the original and updated data if you want. I like to run an identifying query first, so I know hey I should see 87 rows updated or whatever.
Haven't had any issues with table locks with this, but we use Postgres. YMMV.