this post was submitted on 06 Nov 2023
1315 points (98.7% liked)

Programmer Humor

32479 readers
258 users here now

Post funny things about programming here! (Or just rant about your favourite programming language.)

Rules:

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[–] joemo@lemmy.sdf.org 3 points 1 year ago

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.