I have never had to write particularly complex SQL queries, but I’ve written and seen enough to know that that SQL gets nasty and complicated once you start using the non-trivial features, not to mention things like optimizing queries based on the execution plan, or optimizing indexes, or the other million things that make Database Engineer an actual job title.
One thing in particular that has always bothered me (even with my very limited experience!) about SQL is how it tries to read like English, which makes it harder to both read and write in many cases, the simplest and canonical one being that you have to write SELECT ... FROM table
. What table we are querying is the first most important information for any readers, and it’s also the first thing a query writer must decide, yet SQL forces you to write it second. This gets especially annoying when the SELECT
clause is very complex and consists of multiple lines. To illustrate, here is an example I blatantly stole from an SQL tutorial website:
SELECT
SUM (CASE
WHEN dept_id IN (‘SALES’,’HUMAN RESOURCES’)
THEN salary
ELSE 0 END) AS total_salary_sales_and_hr,
SUM (CASE
WHEN dept_id IN (‘IT’,’SUPPORT’)
THEN salary
ELSE 0 END) AS total_salary_it_and_support
FROM employee
The table you are reading from is critical information in giving you the context of what you are looking at and allow you to begin understanding what this query is supposed to be doing, and it’s hidden at the very end of the query.
So yeah, SQL is not the best, and this is where Pipelined Relational Query Language (PRQL, pronounced “Prequel”) comes in and promises to do better: PRQL: a modern language for transforming data (Hacker News thread), promising “a simple, powerful, pipelined SQL replacement”. At a glance, it looks like everything I’d want it to be!
I’m really glad this exists, even though I personally don’t have much use for it at the moment.