r/ProgrammerHumor • • Oct 14 '25

Advanced neverForget

Post image
14k Upvotes

616 comments sorted by

View all comments

2.2k

u/Ghostserver10 Oct 14 '25

I usually never type delete or update. Select first, see what you're about to change only then 

772

u/Hatchie_47 Oct 14 '25

Exactly this, you never wanna run delete or even update without checking the results first - at least on data that matters.

267

u/[deleted] Oct 14 '25

[removed] — view removed comment

57

u/[deleted] Oct 14 '25

[removed] — view removed comment

61

u/droneb Oct 14 '25

I felt a great disturbance in the Force, as if millions of ROWS suddenly cried out in terror and were suddenly silenced

4

u/Zentavius Oct 14 '25

We both had the same thought!

→ More replies (2)

36

u/[deleted] Oct 14 '25

[removed] — view removed comment

45

u/mortalitylost Oct 14 '25

Hey where did you go?

9

u/GradientCollapse Oct 14 '25

Mods should absolutely delete this lmao

4

u/colei_canis Oct 14 '25

You fool, you’ve doomed us all!

→ More replies (1)

3

u/backwardcircle Oct 14 '25

OR, do it inside a transaction. Open transaction, do random shit, validate. If okay comnit, else rollback.

→ More replies (5)

63

u/Titaniumwo1f Oct 14 '25

I always wrap any data modification statement in transaction though, and it always end with rollback unless I really need to commit.

19

u/Brendoshi Oct 14 '25

I do:

Select

Transaction

delete

--rollback

--commit

select

Gives me the data before, the data after (so I can see the changes I've made), and I'll also check the changed rows in case I've been dumb and forgot to account for triggers, and make sure those are all correct.

If I'm happy that the result has done what I want, commit. If I'm unhappy, rollback and rework my statements

0

u/[deleted] Oct 14 '25

[deleted] — view deleted comment

24

u/Haunting-Building237 Oct 14 '25

i'll never trust that lmao

→ More replies (2)

57

u/[deleted] Oct 14 '25

python dev here, i just fuckin

import tables

tables = None
→ More replies (2)

11

u/BroBroMate Oct 14 '25
DELETE FROM X WHERE PK IN (
   SELECT PK FROM X WHERE VERY FUCKING SPECIFIC CLAUSE)

And of course you run the select first. Repeatedly. To be sure.

7

u/gitpullorigin Oct 14 '25

Just don’t press Enter before you typed that WHERE clause

5

u/[deleted] Oct 14 '25

Pretty inefficient since the wrapping delete will use the primary key index on top of all the indices that the sub invoked.

15

u/BroBroMate Oct 14 '25 edited Oct 14 '25

In my experience, and there's a bunch of it, the times you'll be manually executing a DELETE are (or should be) only slightly above zero.

So while you think my DELETE is "pretty inefficient" because I wrote it to fully express my intent, it's actually not inefficient at all, as its efficacy is determined by "Can other people understand my intent", not how fast it deletes data.

If I want or need fast deletion of data, then I'm going to use partitioning and truncate entire partitions at a time - you're focused on the micro, not the macro.

If you need to worry about the performance of your DELETEs, you need to worry about your entire approach to data engineering mate, as efficient data removal doesn't use DELETEs.

You're being penny wise, pound foolish.

3

u/SuitableDragonfly Oct 14 '25

I've worked at places where we never deleted anything, for any reason, and instead just set a soft_delete flag on the row so that the system would treat it as deleted. This isn't GDPR compliant, though.

→ More replies (3)
→ More replies (1)
→ More replies (10)

3

u/LGHTHD Oct 14 '25

Kinda just proving his point eh

→ More replies (25)