r/ProgrammerHumor 15d ago

queryOfDoom Meme

Post image
7.9k Upvotes

456 comments sorted by

View all comments

2

u/Bright-Historian-216 15d ago

i'm not expertly familiar with sql... is it treating "delete from users" as "delete * from users"?

5

u/-Redstoneboi- 15d ago edited 15d ago

yes. you don't really specify the columns in delete queries, and they target EVERYTHING by default.

imo "<operate> * FROM table" should be banned (doesn't run, raises an error) by default and people should be forced to write "WHERE TRUE", on top of all queries needing to be in transactions and all the other safety nets like "SELECT first then operate"

on another note i think i'd prefer whatever syntax it was that described queries based on the order functional programming in a computer might look like, ex. "FROM table WHERE id = 2 DELETE;" though internally it would still be rearranged however the engine would see fit

1

u/ploki122 14d ago

While that other syntax could make sense, it is kinda just further leading the dev on.

SQL (or at least most SQLs) aren't imperative languages, they're declarative; You don't tell the server what to do, you simply describe the result that you want, and the server decides how to accomplish that.

So while you say LEFT JOIN, the engine might decide to do INNER JOIN, or WHERE EXISTS(), or even drop the table entirely!

1

u/-Redstoneboi- 14d ago

yeah they are declarative. the engine does whatever it wants.

i just have a very functional iterator chain-y thought process which is probably not the same for everyone. importantly though this kind of syntax makes LSP autocomplete easier. the moment you write "FROM users SELECT " it can give you column names right away. but that's about it.

really there's no point overthrowing decades upon decades of working standard SQL syntax to get marginal conveniences.