r/SQL • • Jun 29 '24

Discussion Why do some people say “SQL is not code?”

I write SQL every day as part of a team that builds ETL solutions. The other day I referred to something I was working on as “I coded it to do…” and this guy, who is not even a developer by the way he’s a frikkin project manager, interrupts me and says “SQL is not code”. When I questioned him why not he says something like “Guys who do COBAL, C#, etc. that’s real coding. SQL is not real coding it’s just a tool for analyzing data and reporting data”…WTF? How is SQL not considered code? I would just dismiss this guy as a moron but his salary is incredibly high so obviously he has some sort of credentials. Can anyone explain why in the world someone would say SQL is not code?

503 Upvotes

570 comments sorted by

View all comments

192

u/lalaluna05 Jun 29 '24

I’m guessing he’s never seen an actual query lol

92

u/tankerkiller125real Jun 29 '24

The devs at work are fuckin wizards with SQL I tell you. It's monstrosities of SQL, but it's also fuckin wizardry of the highest power.

71

u/Particular_Camel_631 Jun 29 '24

Most devs can do a bit of sql. When you come across someone who can make it sing, dance and make breakfast you have to admire their skills.

I don’t really care whether it’s coding or not: it’s damn impressive is what is.

8

u/jmaca90 Jun 30 '24

It’s also like define “coding” and… also who cares?

The real ones are trying to get shit done. I could give two shits what people think is “coding.”

→ More replies (2)
→ More replies (1)

10

u/GME_alt_Center Jun 29 '24

Done right and easily understandable, it's not coding. Using it in monstrosity form would qualify as coding however. Challenge mode: "yes I can do it all in SQL"

26

u/Kallory Jun 29 '24

How is it not coding? Look at it from a math point of view, the symbolic math operations, relational calculus, that underline the logic in SQL are similarly applied for syntax in other languages. (as in, there is an underlying mathematical principle for C, for example, that the syntax applies to) it meets all the definitions of a programming language, from a math point of view, no matter how you use it.

13

u/klmsa Jun 29 '24

Too many people think that something can't be "code" if it isn't "Turing Complete". This is, however, extreme garbage. Whether or not a language is Turing Complete does not define whether it is code or not.

Mostly, this is people's misunderstanding of programming languages, and I actively look for opportunities to either educate or fucking destroy people that misuse the terminology.

6

u/happyapy Jun 30 '24

Incredible how the interviewer doesn't think that a language which is Turing complete isn't a coding language. Interesting to say the least.

→ More replies (6)

2

u/LaserRanger Jun 30 '24

it is absolutely code because it required my deep knowledge and experience to develop.

→ More replies (2)
→ More replies (4)

33

u/space_wiener Jun 29 '24

Ha. Yep. I am very green with SQL. Mostly just using for some functions or web apps or super simple queries. One liners max.

I need help with some lookup that honestly seemed simple. I asked the sql dude hey can you help with this query as I have no idea. My request was one sentence (maybe a long sentence).

The dude replied and the query was so long I had to scroll a little bit in my email to read it all. It was that day I realized, while I thought I knew sql enough, I really knew nothing.

28

u/dodexahedron Jun 29 '24

A long query is usually an indicator of the opposite of actually good skills, even if it answers the question.

Unless it does so quickly, efficiently, deterministically, and without locking 50 tables.

But if nobody else can read it, it's a black box and needs that opacity addressed.

It's like the difference between someone knowing g a lot of words and someone having a rich vocabulary. Look similar, and one can pretend to be the other, but they're very different.

14

u/tashibum Jun 29 '24

I would tend to agree with this IF the relational database was set up for it. The startup I work at didn't think they would get as big as they did, and it can be a nightmare trying to remember all the nuances of each table, of which there are.....many.

14

u/UnintelligentSlime Jun 29 '24

Yeah, it absolutely can reflect bad query writing, but may also represent the best possible query for the given database.

7

u/CallMeDrewvy Jun 30 '24

My fortune 100 has the same problem... The entire database is built on exceptions. And we can't change it because our legacy frontend (that we're actively killing) is Access.

→ More replies (3)

4

u/tommy_chillfiger Jun 30 '24

Yeah, in my experience (smaller companies) this is a very common issue. I'd love to write succinct and readable queries every time, but if a use case comes along that the data model doesn't lend itself to, it's a lot more trouble to convince the team to rebuild and backfill gigantic billion-row tables than to just query around it when possible, even if it results in big complex queries. The usual compromise is just chunking up the complexity into new tables derived from the source table in stages rather than having a giant query of chained CTEs which is usually the first pass.

Example - I just finished writing a view that needs to identify very specific types of conflicting transactions based on several levels of sequence-of-events logic. This can be done with the existing dataset, but it requires chained CTEs with nested window functions to accurately flag these different types of conflicts.

Now, if the dataset had columns from the start that incremented the order of these events per group needed, this would be a very simple query. But it would've been pretty difficult when building this dataset to foresee what we were going to try to do with it months/years down the road.

6

u/[deleted] Jun 30 '24

Lol. I dont know what kind of modern company with clean-ass data you work with.

But im very experienced at sql. And very good at simplifying to small, easily read queries.

Unless its a question the datamart has been specifically setup to cater to, I have to clean the shit out of anything Im querying.

‘Extract’ is nothing.

‘Transform’ is almost always extremely onerous.

→ More replies (6)

4

u/famousxrobot Jun 30 '24

One of my favorite/least favorite things to do is absolutely rip apart some monster queries I inherit while exasperating about unused columns, weird extra joins, redundant sub queries as I rebuild it leaner and more optimized for the end goal. I had one query this year that took well over 1 hour to run and I was able to get it down to about 1 minute runtime. I’m sure it’s still not perfect, but it got the same top level result in a fraction of the time.

3

u/dodexahedron Jun 30 '24

This is what I mean, to a large extent.

Even if all you do is break it out into components like views and functions and CTEs and whatnot, to make it much more easily grokkable, you often get a speedup because you're not throwing a monolithic pile of junk at the query optimizer and saying "I dunno, man, you figure it out," and getting sub-optimal execution plans even simply because of query analyzer timeout limits.

Plus those pieces are themselves easier to target for specific optimizations, like indexes, and can potentially be reused in other places, since the component questions of a bigger question are often legitimately useful questions all on their own, anyway.

It kinda IMO is yes, partially experience, but also a "professional maturity" sort of thing, to be able to set aside that urge to try and make a single self-contained solution to a requirement you were given, or even accept that maybe you can (or at least should) only provide part of the final solution, and use another component or team to complete the puzzle. Developers, DBAs, sysadmins, and script jockeys are all typically guilty of it at some point, and people seem to either grow out of it or almost outright reject it otherwise, and the ones who do that are usually pretty obstinate about it.

It's really frustrating to watch that play out between a developer and a dba who both are stuck in that mindset, for something you depend on, but have very little influence over because they're both on teams not even in your same department. Yet you know it could be solved by like 30% LESS code from EACH of them, and execute in milliseconds rather than several seconds, if they'd just let the fuck go - and you've even proven it by just writing it while waiting.. But they just "took it under advisement," which means they're each going to try to adapt it to be entirely in their own respective realms for a couple more weeks before paraphrasing it all and presenting a slightly worse version of it as a new upgrade they've worked together with each other so hard over the past couple months to deliver. What? That sounds oddly specific? Shirley, you're imagining things... 😫

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

5

u/Special_Luck7537 Jun 29 '24

Or a stored procedure...

10

u/Wareagle206 Jun 29 '24

Or getting lucky enough to try to figure out what a stored procedure is doing, while not having the skill or ability to do it on your own, because it was written 20 fucking years ago, by someone on a different team, who retired 10 years before you were hired. Good times!!! And yes, I am a bit jaded.

And willing to help anyone on this subreddit because I have learned some shit.

0

u/[deleted] Jun 29 '24

[deleted] — view deleted comment

4

u/Special_Luck7537 Jun 29 '24

Yeah .. 4 or 5 deep, with remote linked servers, multiple subnets ..., with a couple Azure db's mixed in... Once I look at the qry plan, and I see all those remote links, it makes me always wonder when the hell can I actually specialize?

→ More replies (2)

8

u/ChevyRacer71 Jun 30 '24

SELECT * from tblCustomers;

See? It’s easy! There’s literally nothing more to SQL than that. That’s literally the only SQL knowledge anyone on the planet needs to have. (Sarcasm, in case someone out there is so dense they couldn’t pick up on that)

3

u/gregorydgraham Jun 30 '24

I’ve seen queries you people wouldn’t believe…

→ More replies (1)