Remix.run Logo
jakozaur a day 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

tstack a day ago | parent | next [-]

The 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 [2] - https://lnav.org/2024/03/29/prql-support.html

RyanHamilton 19 hours ago | parent | next [-]

If you want to get started with prql check out qstudio https://www.timestored.com/qstudio/prql-ide it allows running prql easily against mysql postgresql duckdb etc

mritchie712 21 hours ago | parent | prev [-]

there's a PRQL extension for duckdb:

https://community-extensions.duckdb.org/extensions/prql.html

da_chicken 14 hours ago | parent | prev | next [-]

While 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.

hamilton a day ago | parent | prev | next [-]

Obviously 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/ [2] https://duckdb.org/2024/11/22/runtime-extensible-parsers.htm...

metadata a day ago | parent | prev | next [-]

Google SQL has it now:

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
ryguyrg a day ago | parent [-]

note that DuckDB allows that reverse ordering (FROM-first)

FROM table SELECT foo, bar WHERE zoo=“goo”

viggity 21 hours ago | parent [-]

it makes intellisense/autocomplete work a hell of a lot easier. LINQ in dotnet does the same thing.

crooked-v a day ago | parent | prev | next [-]

I suspect you'll like PRQL: https://github.com/PRQL/prql

wodenokoto a day ago | parent | prev | next [-]

I haven’t tested but I believe there’s a prql extension for duckdb

NDizzle 4 hours ago | parent | prev | next [-]

This is the stuff nightmares are made out of. Keep that style of coding out of any project I’m involved in, please.

sidpatil 2 hours ago | parent [-]

What do you dislike about that style?

bb86754 an hour ago | parent [-]

He/she isn't used to it. Any R, Elixir, or F# developer would be right at home with this syntax.

cdchhs 14 hours ago | parent | prev [-]

that syntax is horrendous.