News for hackers. Stuff that matters.
Re:SQL should be your default choice for data engineering pi... by philmcp on Monday January 30, 2023 @09:59AM (#34580392)
I'd say SQL is the most underrated engineering skill out there.

It amazes me when competent developers / analysts / data scientists don't know (any) SQL. Have they stopped teaching this in University or something?

Re:SQL should be your default choice for data engineering pi... by mritchie712 on Monday January 30, 2023 @10:36AM (#34581032)
I think it's bc of how popular ORM's are. You can get pretty far with an ORM without knowing any SQL, but you can inadvertently do some really dumb things if you don't understand how SQL works.
Re:SQL should be your default choice for data engineering pi... by randomdata on Monday January 30, 2023 @10:48AM (#34581234)
SQL was the first language I ever learned, so perhaps my perspective is skewed, but it seems like it would be pretty hard to use an ORM without gaining an intuition into how SQL works.

What is a trap I see often among ORM users is them running into the n+1 problem. However, that's actually a consequence of database implementations not being theoretically pure. If you had an ideal SQL database then their approach would be technically correct. They aren't wrong to think that way.

It's just that we don't have ideal SQL databases, so we have to resort to hacks to make things work in the real world. Why we need to break from the theoretical model and use those hacks can be difficult to understand if you aren't familiar with the implementation at a lower level.

Re:SQL should be your default choice for data engineering pi... by cnity on Monday January 30, 2023 @11:22AM (#34581906)
ORMs are funny: people say that they are great for the simple stuff (scans with simple joins and filters). But those cases are just that: simple!
Re:SQL should be your default choice for data engineering pi... by toolslive on Monday January 30, 2023 @12:10PM (#34582879)
"Object/Relational Mapping is the Vietnam of Computer Science. It represents a quagmire which starts well, gets more complicated as time passes, and before long entraps its users in a commitment that has no clear demarcation point, no clear win conditions, and no clear exit strategy." (Ted Neward)
Re:SQL should be your default choice for data engineering pi... by doctor_eval on Monday January 30, 2023 @04:40PM (#34586819)
Dear God. 1000x this.
Re:SQL should be your default choice for data engineering pi... by nativecoinc on Monday January 30, 2023 @05:01PM (#34587061)
What a gross quote.
Re:SQL should be your default choice for data engineering pi... by wvenable on Monday January 30, 2023 @12:30PM (#34583237)
Remember an ORM is an object-relational mapper not a query builder. The "simple stuff" is repetitive, extremely common, straight forward, and boring -- exactly the sort of thing you want to automate.
Re:SQL should be your default choice for data engineering pi... by mattmanser on Monday January 30, 2023 @01:12PM (#34583945)
Yeah, but when you add/change a new property to your most used class you don't have to change 500 odd SQL statements, it just works.

That's what's amazing about ORMs handling the simple stuff.

Re:SQL should be your default choice for data engineering pi... by randomdata on Monday January 30, 2023 @01:38PM (#34584355)
> Yeah, but when you add/change a new property to your most used class you don't have to change 500 odd SQL statements, it just works.

ORM doesn't have anything to do with SQL statements. ORM only operates on the results those SQL statements produce.

You're probably thinking of the active record pattern, which combines ORM with query building into an interesting monstrosity. Indeed, query builders produce SQL statements and can save you from changing 500 odd raw SQL queries.

Re:SQL should be your default choice for data engineering pi... by andix on Monday January 30, 2023 @04:54PM (#34586976)
A lot of ORMs create SQL statements too, they have an integrated query builder. And functionality for updating, deleting and even creating/modifying schemas (migrations).

But as always: use the right tool for the job. A hammer is a great tool, but not suitable for removing screws (most of the time).

Re:SQL should be your default choice for data engineering pi... by randomdata on Monday January 30, 2023 @05:18PM (#34587285)
> A lot of ORMs create SQL statements too, they have an integrated query builder.

These are technically active record libraries. One of the popular ones is literally known as ActiveRecord, but the whole suite of them are implementations of the active record pattern.

ORM is simply the process of converting relations (i.e. sets of tuples, i.e. rows and columns) into structured objects and back again. This layer of concern is independent of query generation.

Re:SQL should be your default choice for data engineering pi... by mattmanser on Friday February 03, 2023 @12:32PM (#34644596)
What everyone's talking about here is what is commonly referred to as an ORM by everyone apart from you, apparently.
Re:SQL should be your default choice for data engineering pi... by andix on Monday January 30, 2023 @04:21PM (#34586548)
ORMs are not only great for simple stuff. They are great for a lot of complicated queries too. But as always, you need to know what you’re doing. An ORM is not a magic layer, that solves all of your problems.

I’m mostly using entity framework core, which allows you to do quite complex queries, which can be really easy to read and maintain. But if you’re careless, you can create quite slow queries, that’s clear. But you can easily create slow queries with plain SQL too.

Re:SQL should be your default choice for data engineering pi... by doctor_eval on Monday January 30, 2023 @04:42PM (#34586842)
Yes, I’ve found that it’s possible to write hundreds of lines of ORM code to do some very complex and sophisticated processing, that could be done in a dozen lines of plain SQL.
Re:SQL should be your default choice for data engineering pi... by andix on Monday January 30, 2023 @04:51PM (#34586946)
Good ORMs let you use SQL statements wherever you need them. Go for it, if it’s easier, and let the ORM just map the results to objects.

And nothing prevents you from using plain SQL libraries next to an ORM. Good ORMs expose the database connection, so you can do whatever you want.

Every tool can be abused.

Re:SQL should be your default choice for data engineering pi... by doctor_eval on Tuesday January 31, 2023 @02:40AM (#34592424)
The ORMs I’ve used also needed every entity from the database to be duplicated in the host language, which is a horrific amount of duplication in any non trivial project. And then they need to be kept in sync. And then they have these horrendous caching issues that mean if you fall back to SQL then you take a massive performance it.

ORMs are an inefficient, leaky and slow abstraction layer on top of a fast and complete abstraction layer. I’ll never willingly use an ORM again.

Re:SQL should be your default choice for data engineering pi... by andix on Monday February 06, 2023 @09:34AM (#34677771)
There are two ways to achieve a single source of truth:

1. Generate ORM entities from the database (usually there is a too for that) 2. Generate the database from ORM entities, and make changes via generated/manual migrations

You are supposed not to edit the generated side, just re-generate it on a change of the model.

Re:SQL should be your default choice for data engineering pi... by whoopdeepoo on Monday January 30, 2023 @07:29PM (#34588983)
Every single org I've found that says "we don't use ORMs because they're slow" ends up constructing their own bespoke, wheel-reinventing "orm" or sticks all their application logic in sprocs, which are nightmares for imperative logic.
Re:SQL should be your default choice for data engineering pi... by listenallyall on Monday January 30, 2023 @09:22PM (#34590063)
I don't think it's the syntax of SQL that causes problems (and which ORMs try to replace)... it's the complex underlying logic necessary to accurately join multiple tables, set where and having conditions, and aggregating records, and knowing to which dataset each should apply.

Countless "replacements" for SQL have come around to make data accessible by non-expert, but regardless if your using a BI tool, reporting platform, ORM, whatever, pretty soon you're going to need to understand and express the logic, and that's when you really appreciate SQL's directness and terseness.

Re:SQL should be your default choice for data engineering pi... by Kon-Peki on Monday January 30, 2023 @10:08AM (#34580521)
My memory could be a little hazy, but I don't remember any required course that dealt with SQL when I was in the CS program at a pretty highly-regarded university 25 years ago.

I took a course in which I learned quite a lot about SQL and in retrospect it was an extremely useful course to have taken.

Re:SQL should be your default choice for data engineering pi... by SCdF on Monday January 30, 2023 @10:34AM (#34580994)
We did some in CS101/102 (first year required CS courses). Specifically normalised forms and the like.
Re:SQL should be your default choice for data engineering pi... by robertlagrant on Monday January 30, 2023 @11:24AM (#34581939)
We had to do it in the UK, circa 20 years ago.
Re:SQL should be your default choice for data engineering pi... by ncphil on Monday January 30, 2023 @12:58PM (#34583709)
I avoided learning SQL in the client-server training program that got me started in tech back in the late 90s, only to have to learn it on the job during a global ERP deployment a decade later. Should have taken the class, would have meant at least a few less sleepless nights.
Re:SQL should be your default choice for data engineering pi... by icedchai on Monday January 30, 2023 @11:45AM (#34582381)
I remember taking a databases class (either junior or senior year) that covered database design and also SQL with Oracle. We even got into Pro*C, which was some crazy Oracle-specific C pre-processor. It definitely wasn't required. My roommate took it and failed.
Re:SQL should be your default choice for data engineering pi... by edejong on Monday January 30, 2023 @02:58PM (#34585526)
At a Dutch CS study we had an SQL course that started with first-order logic, relational algebra and went to on to project that into SQL. It also taught 3NF/4NF and BCNF, indices, r-trees, query planning and optimisation.
Re:SQL should be your default choice for data engineering pi... by Kon-Peki on Monday January 30, 2023 @03:39PM (#34586033)
Was this a required or elective course?

The one I took was elective. I am willing to admit that from a professional ROI perspective, it was one of the best uses of time in my entire life and easily worth hundreds of thousands of dollars.

Re:SQL should be your default choice for data engineering pi... by edejong on Friday February 10, 2023 @06:40PM (#34747612)
Required.
Re:SQL should be your default choice for data engineering pi... by Izkata on Monday January 30, 2023 @10:13PM (#34590393)
Mine ~15 years ago in the US had a required course that did some relational algebra and database normalization without ever touching a database (as a small part of a broader course, IIRC), and an elective where we did really simple stuff with a database (I came out of it not really understanding the difference between INNER JOIN and LEFT JOIN, for example).
Re:SQL should be your default choice for data engineering pi... by maerF0x0 on Monday January 30, 2023 @10:25AM (#34580847)
Anecdata point here, personally my SQL skills have lapsed because I've been incentivized to know NoSQL more. Same for frontend stuff like JS/React btw.
Re:SQL should be your default choice for data engineering pi... by giraffe_lady on Monday January 30, 2023 @10:19AM (#34580754)
I think one of the main uncertainties in higher education the last couple decades is what balance, if any, they should strike between job training for software developers, coding as an engineering discipline, and preparation for an academic career in math.

Most programs include parts of all three, but SQL per se (rather than like, relational algrebra) is pretty firmly in the professional training for software developers set, and schools that reject that aspect may not teach it.

In my experience recent code school/boot camp grads have as much or more practical sql as recent CS grads; probably because those schools are nearly totally focused on professionally applicable skills.

Re:SQL should be your default choice for data engineering pi... by cmrdporcupine on Monday January 30, 2023 @11:17AM (#34581803)
That may be likely, but then schools which emphasize the math/theory part are then missing the opportunity to really teach the theoretical part of the relational algebraic stuff; which is really set theory and first order logic. There's a lot of math-y stuff to dig into there.

It should be mandatory along with understanding O notation and datastructures and algorithms, because really... unless you're doing a career which is like... 100% embedded development... you're going to be encountering databases and datamodeling as part of your career.

I'd be much happier if CS programs would graduate people who did a whole semester of first order logic, Date&Codd's foundational papers and why network&hierarchical databases are problematic, relational algebra / calculus, Datalog & friends, and then just toss in a "and this is how SQL does some of this but also mangles all of this..." at the end.

+ as a bonus, a DB implementation/internals course so people can understand what goes into query execution etc.

Because those people would then have some proper context before going off and butchering the world with ORMs and microservices...

Re:SQL should be your default choice for data engineering pi... by spaniard89277 on Monday January 30, 2023 @11:55AM (#34582564)
In my bootcamp (Spain) SQL is not widely-teached but there's a course about it (with Postgre) and you see something from time to time.

But AFAIK so does my local university.

Re:SQL should be your default choice for data engineering pi... by cmrdporcupine on Monday January 30, 2023 @11:14AM (#34581738)
Database education in CS programs in North America seems minimal. Most people I meet haven't taken any, or maybe just took a practical "how to query" course. In North America, it seems like only CMU has an active (excellent) program around this topic.

There's a woeful ignorance about what the relational data model is, how the industry arrived here, and how this is implemented. Problems or archaisms with SQL specifically become synonymous in people's heads with the relational model generally, and for a while that led down the quite problematic NoSQL road. Then slingshotted back to SQL -- but from my perspective SQL itself (not the relational model) is a problem. It doesn't compose well. It doesn't handle recursive relations well. It has an awkward syntax. It conflates concepts. It has an archaic datatype model. None of this is intrinsic to the relational model, but SQL becomes a limiting factor.

Disclaimer: I work for a DB company doing awesome stuff with the relational data model, but not SQL (RelationalAI) so am ... biased. Though I have always had those biases. :-)

Re:SQL should be your default choice for data engineering pi... by michaelmior on Monday January 30, 2023 @12:28PM (#34583192)
I'm a faculty member at the Rochester Institute of Technology. We have multiple courses for both our undergrads and grad students in databases. I primarily teach Introduction to Big Data for our graduate students. We happen to cover all the things that you mention in your second paragraph :)
Re:SQL should be your default choice for data engineering pi... by cmrdporcupine on Monday January 30, 2023 @12:50PM (#34583585)
What % of students graduate without taking those courses?
Re:SQL should be your default choice for data engineering pi... by michaelmior on Monday January 30, 2023 @01:57PM (#34584676)
Undergraduate students are required to take an introductory database course. Graduate students are not, but a significant fraction do.
Re:SQL should be your default choice for data engineering pi... by throwaway23597 on Monday January 30, 2023 @11:36AM (#34582203)
IMO there's a big difference between university level SQL and the ability to competently write SQL in a professional setting. In university, at least at my school, you are getting maybe at most 3 tables overall, with 3-5 columns each. Professionally, you're dealing with hundreds, maybe thousands of tables, each with between 10-1000 columns, and usually not even in 1NF either. It really takes a lot of practice writing queries professionally to get to a level of competence here.
Re:SQL should be your default choice for data engineering pi... by alephxyz on Monday January 30, 2023 @11:55AM (#34582569)
I've worked with many data scientists whose typical SQL usage was to load entire rows (or with simple 'with' filtering) into Pandas / R dataframes and then do all their work there. I think it's a combination of Pandas and R having much simpler APIs and a ton of documentation on Stack Overflow, and modern hardware just being so good that you can load a big enough chunk of your dataset in-memory on a laptop.
Re:SQL should be your default choice for data engineering pi... by VeninVidiaVicii on Monday January 30, 2023 @12:36PM (#34583354)
Guilty! I live in data.table in R, which is essentially an ideological implementation of SQL, but with much terser syntax.

https://cran.r-project.org/web/packages/data.table/vignettes...

Re:SQL should be your default choice for data engineering pi... by waffletower on Monday January 30, 2023 @01:57PM (#34584677)
Never feel guilty using that superior workflow, when your dataset can comfortably resides in memory.
Re:SQL should be your default choice for data engineering pi... by bigger_cheese on Monday January 30, 2023 @08:02PM (#34589314)
I mostly use SAS, I tend to prefer using plain sql queries where I typically depart SQL and jump into code is doing what SAS calls "By Group processing" (example https://support.sas.com/kb/26/013.html#)

I am not as familiar with R. Last time I worked in R (some years ago) equivalent R code was something like this caution I'm no expert in writing R so might be a better /more intuitive way...

Output_data <-merge(x=T1, y=T2, by="Date", all.x="True") %>% mutate(My_var = NAME) %>% fill(My_var)

In SQL the equivalent would need to use Over (Partition by) which is less intuitive for me to write.

Re:SQL should be your default choice for data engineering pi... by o_nate on Tuesday January 31, 2023 @11:48AM (#34597534)
Hard for me to imagine anyone who finds Pandas API more intuitive than plain old SQL. I can't do anything in Pandas without looking up syntax.
Re:SQL should be your default choice for data engineering pi... by cess11 on Monday January 30, 2023 @12:27PM (#34583181)
My programme in high school allowed me to choose a course in SQL, that's how I first learned it in 2002.
Re:SQL should be your default choice for data engineering pi... by pc86 on Monday January 30, 2023 @12:38PM (#34583392)
I'm not sure you can call those folks competent if they can't interact with a database unless you give them an ORM.
Re:SQL should be your default choice for data engineering pi... by waffletower on Monday January 30, 2023 @02:03PM (#34584773)
The issue isn't usually competency, can vs. cannot. It is usually a matter of should or should not. I have seen databases thrown at problems where they decidedly should not have, and have seen the product development cycle suffer where it should not have. While some engineers and analysts relish CTE spaghetti -- solving complex logic utilizing enormous wads of SQL, others are more wary and rightly look to tackle complexity with more accountable and powerful tools when possible. I admit that tools like DBT can help address some of the shortcomings of SQL, but it still does not have the generality and conciseness of modern languages.
Re:SQL should be your default choice for data engineering pi... by LarryMullins on Monday January 30, 2023 @01:49PM (#34584533)
> Have they stopped teaching this in University or something?

It wasn't part of the mandatory coursework when I went to school. I really think it should be. It's not as though my CS program was 'pure theory', they taught lots of 'vocational' stuff but not SQL.

As for why people put off learning it.. I put off learning it longer than I care to admit because I thought I could simply do without it (ORMs, BerkeleyDB, etc), and fake it if put on the spot (I always understood the very basics, insofar as a SQL query can be understood if read as declarative English.) Ever since I bit the bullet and actually learned it properly, I've been kicking myself for not learning it upfront.