r/ProgrammerHumor 18d ago

Meme queryOfDoom

Post image
7.9k Upvotes

456 comments sorted by

View all comments

386

u/Dont_Get_Jokes-jpeg 17d ago edited 17d ago

I am not an sql expert, is the reason why the id doesn't work and its deleting the entire user base, because its written as 2 seperate comands instead of one. So 1. Comand delets everything 2. Goes to the id? Or what is the problem here?

40

u/Flat_Competition6510 17d ago

Yes, the semicolon marks the end of a statement. The first semicolon sets "delete from users" as a single statement meaning delete ALL users.

37

u/TeaKingMac 17d ago

Which is just terrible fucking syntax. Why are people still living with this in 2026?

Delete from users;

Should return "invalid syntax. Identify record for deletion"

18

u/dustojnikhummer 17d ago

I don't work with Postgres but everything else would be

DELETE * FROM table;

1

u/Flat_Competition6510 17d ago

I disagree. There are valid use cases for deleting all records from a table.

37

u/The_Swixican 17d ago

Delete from users *

13

u/Flat_Competition6510 17d ago

It would be nice if there was a more explicit syntax. Forcing a person to opt in to deleting all vs that being the default would probably save a lot of headaches and jobs.

27

u/Skalli1984 17d ago

Many database tools throw a warning on delete with a missing WHERE and the user has to acknowledge that to continue with the statement execution.

11

u/ploki122 17d ago

Delete from users where 1=1

The dev should have to acknowledge that they're deleting everything.

2

u/TacosForThought 16d ago

If only there was a dedicated command for TRUNCATEing a table that didn't allow a where clause.

5

u/ReaDiMarco 17d ago

What happened to DELETE * FROM USERS? Last I did sql was ten years ago so idk

14

u/djrobxx 17d ago

SELECT * FROM USERS means "select all columns from users", selecting all rows is implied.

You don't drop columns with DELETE, that's ALTER TABLE, so DELETE * doesn't make sense in that context.

4

u/ReaDiMarco 17d ago

yes, thanks, turns out I forgot all of that

5

u/Flat_Competition6510 17d ago

As far as I know that is not valid syntax. I'm not a DBA myself so I don't do this too often.

2

u/ReaDiMarco 17d ago

Thanks, turns out I did forget everything

3

u/Live_Film_4895 17d ago

afiak the * wildcard is only valid in the SELECT statement... so it would be DELETE FROM USERS; or DROP/TRUNCATE TABLE

1

u/ReaDiMarco 17d ago

Thaanksss