3 ms·
It would be even better if SQL had pipe syntax. SQL is amazing, but its ordering isn’t intuitive, and only CTEs provide a reliable way to preview intermediate r
by jakozaur 1y ago
It would be even better if SQL had pipe syntax. SQL is amazing, but its ordering isn’t intuitive, and only CTEs provide a reliable way to preview intermediate results. With pipes, each step could clearly show intermediate outputs.
Example:
FROM orders
|> WHERE order_date >= '2024-01-01'
|> AGGREGATE SUM(order_amount) AS total_spent GROUP BY customer_id
|> WHERE total_spent > 1000
|> INNER JOIN customers USING(customer_id)
|> CALL ENRICH.APOLLO(EMAIL > customers.email)
|> AGGREGATE COUNT(*) high_value_customer GROUP BY company.country
- metadata 1y agoGoogle SQL has it now: https://cloud.google.com/blog/products/data-analytics/simplify-your-sql-with-pipe-syntax-in-bigquery-and-cloud-logging https://cloud.google.com/blog/products/data-analytics/simpli... It's pretty neat: FROM mydataset.Produce |> WHERE sales > 0 |> AGGREGATE SUM(sales) AS total_sales, COUNT(\*) AS num_sales GROUP BY item; Edit: formatting
- crooked-v 1y agoI suspect you'll like PRQL: https://github.com/PRQL/prql https://github.com/PRQL/prql
- hamilton 1y agoObviously one advantage of SQL is everyone knows it. But conceptually, I agree. I think [1]Malloy is also doing some really fantastic work in this area. This is one of the reasons I'm excited about DuckDB's upcoming [2]PEG parser. If they can pull it off, we could have alternative dialects that run on DuckDB. [1] https://www.malloydata.dev/ https://www.malloydata.dev/ [2] https://duckdb.org/2024/11/22/runtime-extensible-parsers.html https://duckdb.org/2024/11/22/runtime-extensible-parsers.htm...
- wodenokoto 1y agoI haven’t tested but I believe there’s a prql extension for duckdb
- tstack 1y agoThe PRQL[1] syntax is built around pipelines and works pretty well. I added a similar "get results as you type" feature to the SQLite integration in the Logfile Navigator (lnav)[2]. When entering PRQL queries, the preview will show the results for the current and previous stages of the pipeline. When you move the cursor around, the previews update accordingly. I was waiting years for something like PRQL to implement this since doing it with regular SQL requires more knowledge of the syntax and I didn't want to go down that path. [1] - https://prql-lang.org https://prql-lang.org [2] - https://lnav.org/2024/03/29/prql-support.html https://lnav.org/2024/03/29/prql-support.html
- mritchie712 1y agothere's a PRQL extension for duckdb: https://community-extensions.duckdb.org/extensions/prql.html https://community-extensions.duckdb.org/extensions/prql.html
- RyanHamilton 1y agoIf you want to get started with prql check out qstudio https://www.timestored.com/qstudio/prql-ide https://www.timestored.com/qstudio/prql-ide it allows running prql easily against mysql postgresql duckdb etc
- cdchhs 1y agothat syntax is horrendous.
- da_chicken 1y agoWhile I would certainly agree with you that putting the FROM clause first would be a significant improvement to SQL and was a genuine design mistake, this otherwise feels more like just wanting SQL to be less declarative and more imperative. Wanting it to be more like LINQ and less like relational algebra. That, I think, is most developers' real sticking point with SQL. It's not object-relational impedance mismatch between their application and the data store, it's imperative-declarative impedance mismatch between their preferred or demonstrated talent. They are used to thinking about problems in exactly one way, so when they struggle to adapt to a different way of thinking about the problems they assume their familiarity is what's more correct. I think this is why the same developers insist that XML/HTML is "just a markup language." Feeding a document into an executable to produce output isn't really significantly different than feeding imperative language into a compiler. The only real difference is that one is Turing complete, but Turning completeness is not a requirement of programming languages.
- NDizzle 1y agoThis is the stuff nightmares are made out of. Keep that style of coding out of any project I’m involved in, please.