Live data from Hacker News

Learn SQL Once, Use It for 30 Years

fagnerbrack.com

111–120 of 243 posts

Re: Learn SQL Once, Use It for 30 Years

#111

>The Only Programming Language Built on Mathematics, Not Fashion As a modern array language D4M is the natural successor for SQL [1]. D4M is based on mathematics like SQL, specifically associative array algebra but not relational unlike SQL. It's more generic since can it caters to most modern data abstractions including spreadsheets, database tables, matrices, and graphs [2]. You can achieve 100M database inserts pe…

This seems like just another NoSQL db, but with fancier words.

Re: Learn SQL Once, Use It for 30 Years

#112
post #38

I’ve always felt that SQL is somewhat easy to grasp for basic queries, but gets complex and difficult for even moderate to higher complexity use cases. My eyes glaze over when I read long stored procedures that someone else has written. Any recommended resources to go from beginner/beginner-intermediate to advanced?

I think advanced SQL authoring is generally simple to understand, and that's the larger learning curve!

I find those big stored procedures usually fall into two categories; logic that should be in the DB, but should be decomposed (staging tables, other SPs, etc) in which case they can be understandable in chunks; or logic that shouldn't be in the DB but has been shoved in there, in which case there's more of an ideological debate but I generally prefer to pull out and run in the application layer. (the latter is pretty much IMO the things that you've done after you've gotten the data at the right grain, when you are massaging it to a particular form/presentation format; performance is often the final arbitre here though).

Re: Learn SQL Once, Use It for 30 Years

#113

I’d say the most impactful thing is not to learn SQL, but set theory. Well-written SQL is about thinking in sets. I cannot tell you how many poorly written procedural stored procedures I’ve replaced with a single performant SQL query over the years. This is because the most impressive part of the SQL ecosystem is the DBMS engine’s query plan. Though, yes, you have to know how to influence it. I find ORMs also tend to…

I think I had a pretty good understanding of set theory through programming, and although I tried to get into the more mathematical side of it, I found most things to be 1. trivial (because I was used to thinking in lists, sets, hashmaps, etc.), or 2. irrelevant to me. The latter was a shame, because I've always liked the abstraction of math, but I couldn't help but feel I wasn't learning anything actionable when learning more about sets (though maybe I'm wrong).

What had a big impact on me was the relational model, specifically after reading Richard Fabian's Data-oriented Design book [1]. I had watched Mike Acton's famous Data-oriented Design talk [2], then Andrew Kelley's talk [3] where he explains speedups in the Zig compiler using DoD principles (largely using methods from Acton's talk), but Fabian's book tied these concepts to database normalization and the relational model.

Most DoD advice is very "exercise left to the reader", because it's about matching a specific problem, but using the relational model and considering your data's primary and foreign key relations can be really powerful. I just wish more of that power was exposed through regular programming language interfaces, rather than having to pull in and marshal data through a DB. I might have to try C# and Linq.

1. https://www.dataorienteddesign.com/dodbook/

2. https://www.youtube.com/watch?v=rX0ItVEVjHc

3. https://www.youtube.com/watch?v=IroPQ150F6c

Re: Learn SQL Once, Use It for 30 Years

#114
post #43
post #37

Earlier quoted context omitted.

A couple of sites worth checking out to level up, both by Markus Winand: https://modern-sql.com/ https://use-the-index-luke.com/

also a few different para-sql languages that can be useful, to lower the complexity: - https://prql-lang.org/ - https://www.malloydata.dev/

A self para-sql-lang plug if you like the direction of malloy but prefer something closer to native SQL syntax. (a controversial take at times)

- https://trilogydata.dev/

Re: Learn SQL Once, Use It for 30 Years

#115

Not quite as simple as learning it once. SQL evolves like other languages, across vendor implementations. The ClickHouse and DuckDB dialects for example extend the language with analytic options not found in ANSI SQL, nor T-SQL, Pl/PgSQL, etc. DuckDB QoL enhancements are greatly missed when not available.

Which SQL-specific QoL enhancements do you miss? I was really excited to use DuckDB for things like structs and enums, but after a while I just went back to regular SQL and used it for its other features.

Re: Learn SQL Once, Use It for 30 Years

#116
post #10

Just, for god's sake, move SELECT after GROUP BY, I beg you.

Current structure makes sense to me. SELECT .... what do I want FROM .... where is it WHERE .... what filters do I want to apply GROUP BY .... how do I want it aggregated Maybe it's just that I'm so used to it. I could see FROM being first, that would actually make a little more sense to me.

A pretty common request is to lift the FROM up before the select, like the below. I'm pretty fine with status quo since my mind is usually "hmm what do I need to get" first, then I figure out how to get it, but some engines (duckdb, I think?) support both so everyone gets their cake.

What people often want:

Re: Learn SQL Once, Use It for 30 Years

#118
post #20

Everyone knows SQL already. The harder parts that pay off are schema design, knowing how to interact with your DB in code, and knowing all the ins and outs of whatever DBMS you're using.

I would emphasize the importance of batching and set operations. This is where I think many developers lose track of the rabbit, because you don't have much control over either of these things via ORMs. You have to get your hands dirty with raw command text. The value of this stuff is difficult to overstate. Batching allows for you to rapidly load the RDBMS. The first few times you test, it will probably go so fast y…

There's always a bulk insert, but I wouldn't say every engine has always had a reasonable way to bulk load truly large data... parquet really helped with interop but before that when your best option was a CSV and bcp life was not fun.

Re: Learn SQL Once, Use It for 30 Years

#119

I think the pretext of this articles is ridiculous. Yes, SQL is based around relational algebra, but all programming languages are built on a theoretical foundation. And SQL is very much a "fad" language - it just somehow managed to stick around. The goal was not some sort of mathematical purity, but rather to built a natural language data interface (sounds like something currently very hyped?) and it failed spectacu…

> Sometimes '=' is an identity test, sometimes it is `==`.

Eh... Where did you find `==` used in SQL?

Post reply on HN