DEV Community

Discussion on: 10 Things I Hate About SQL

Collapse
 
shaqq profile image
Shaker Islam • Edited

Thanks for responding, @rolandbouman

Now, typically you'd want to push this type of formatting to a reporting tool. But if you really want to do it in a query, you'd simply use a built-in date formatting function. And, you'd make your life considerably easier by storing the publish_year as a date.

With respect, this is a classic example of "this isn't the product's problem, it's the user's problem." Yes, of course - users have been dealing with this and using workaround for years now. My question is - can this be better?

variables are an imperative device and in many cases using them would force a definite execution order, which makes it harder (impossible) to optimize the query

You're saying it's impossible to have some sense of variables in SQL, with some sane guardrails, and be able to optimize a query? I doubt that, given that there are SQL dialects that have variables.

If dividing one number by another static number is an execution that must be done before others, I think that's a fine tradeoff for most/all users. There must be a better way.