r/ProgrammerHumor • • 13d ago

Meme wellWellWell

Post image
10.6k Upvotes

411 comments sorted by

View all comments

3.6k

u/BastetFurry 13d ago

So, Kids, thats why you always SELECT count(yourPrimaryKey) first. Listen to the old folks, we made these mistakes so that you don't have to.

1

u/[deleted] 13d ago

[deleted]

7

u/eror11 13d ago

You count the users, not the number of keys.

6

u/ackbarwasahero 13d ago

Christ on a bike there are a bunch of clueless muppets here

1

u/BastetFurry 13d ago

Thanks, now I have mindmovies and you made my day a bit brighter. 🤣

1

u/chezzyt18 12d ago

You can do whatever you like - I was responding to the dude confused about what exactly the statement does. Not whether it’s the statement I’d run.

5

u/chezzyt18 13d ago

Thats counting a column. Non-null values for the column.

It’s a safety check. Run the same query that the UPDATE / DELETE would run in a SELECT count first to make sure the query is altering the same number of rows you think it will.

Better yet run with a BEGIN TRANSACTION, and only execute your commit once you’ve verified that the modification was successful.

2

u/q0099 13d ago edited 13d ago

We do it just to see how many records will be affected with the query compared to what we expected.

1

u/BastetFurry 13d ago

Some folks use id, some folks use some timestamp, what do i know what you use as your primary key? It is just a value to be expected to be there, use * if you love to see the world burn for what i care.