Really intriguing article about a SQL syntax extension that has apparently already been trialed at Google.

As someone who works with SQL for hours every week, this makes me hopeful for potential improvements, although the likelihood of any changes to SQL arriving in my sector before I retire seems slim.

11 points

“|>”? Why? That’s such a difficult combination to type and it seems entirely unnecessary.

permalink
report
reply
5 points

It’s used that way in Elixir. I don’t find it a problem.

permalink
report
parent
reply
5 points

It’s unnecessary, though - the keywords alone are sufficient. I dislike “clutter” syntax.

permalink
report
parent
reply
0 points

Possibly unpopular opinion: more languages should embrace unicode symbols in their syntax with multi-character ascii equivalents like Raku did. I set my vim config to automatically replace the ascii version with unicode. It wasn’t hard, it makes the code a little more compact, and with good character choices, it stands out in an understandable way.

permalink
report
parent
reply
4 points

F# also does that

permalink
report
parent
reply
2 points
*

In Clojure, -> is used for inserting the piped argument at the head position in the arguments of whatever it is passed to, while ->> is used for inserting it at the tail. This approach is great for working with immutable data in a series of approachable transformations, which I believe is one reason why so many Domain-Specific Languages for generative programming are written in that language, aside from its interactive REPL. Additionally, there is no need to worry about excessive copying, as this is generally well optimized.

This can be particularly useful with HoneySQL, which is more of a DSL for SQL rather than a typical ORM tool. For example:

(defn apply-filters [query filters]
"applies WHERE clauses to a query"
  (reduce (fn [q [column value]]
            (helpers/where q [:= column value]))
          query
          filters))

(defn build-dynamic-query [{:keys [table columns filters sort-by limit]}]
  (-> {}
      (helpers/select columns)
      (helpers/from table)
      (apply-filters filters)
      (helpers/order-by sort-by)
      (helpers/limit limit)
      sql/format))

;; Result - a super readable function call that resembles a natural language 
(build-dynamic-query 
  {:table :products 
   :columns [:id :name :price] 
   :filters {:category "electronics" :in-stock true}
   :sort-by [:price :desc]
   :limit 20})
permalink
report
parent
reply
0 points

CTRL+ALT+<, SHIFT+<

🙃🤡

permalink
report
parent
reply
11 points

So like LINQ?

permalink
report
reply
10 points
*

I find LINQ query syntax less readable than SQL. I like LINQ method syntax for simple, linear queries.

The linear method syntax is somewhat like the idea of piping SQL operations.

permalink
report
parent
reply
1 point

I just threw up in my mouth a little. Do we have content warnings here? We should get content warnings here. It’s been three blessed years since I thought about the pile of crap that is LINQ. Here’s to three more!

permalink
report
parent
reply
5 points

“Maybe our friend doesn’t like monads.”

permalink
report
parent
reply
6 points

The reorganization of statements is excellent but the pipe operator itself is unnecessary and annoying. It’d be far better to just rearrange the clauses and call it a day, relying on the keywords that are still present to signify clause termination…

Especially once we get into subqueries and CTES, I never want to write:

|> LEFT JOIN |> FROM foo |> GROUP BY clusterid |> SELECT clusterid, COUNT(*)
      ON cluster.id = foo.clusterid

And I’m also not splitting out a trivial subselect like that into four lines because I respect my reader.

permalink
report
reply
4 points

I find dplyr in R to be pretty reasonable.

https://cran.r-project.org/web/packages/dplyr/vignettes/dplyr.html

I don’t know if that’s what the article is referring to by “other data languages”.

permalink
report
parent
reply
2 points

What about respecting the reader of the diff when there’s a change in the middle?

permalink
report
parent
reply
2 points

If this is something likely to change I’d space it out - but mid-line diffs are usually pretty readable in most clients.

As always, expression should cater to readability and shouldn’t be limited by syntax rules.

permalink
report
parent
reply
2 points
*

No matter which tool you’re using, this:

- |> LEFT JOIN |> FROM foo |> GROUP BY clusterid |> SELECT clusterid, COUNT(*)
+ |> LEFT JOIN |> FROM foobar |> GROUP BY clusterid |> SELECT clusterid, COUNT(*)
      ON cluster.id = foo.clusterid

Is always less readable than:

  |> LEFT JOIN 
- |> FROM foo 
+ |> FROM foobar
  |> GROUP BY clusterid 
  |> SELECT clusterid, COUNT(*)
      ON cluster.id = foo.clusterid

And this isn’t even the worst example I’ve seen. That would be a file that had a bug due to duplicated entries in a list, and it became very obvious as soon as I converted it to something akin to the second version.

permalink
report
parent
reply
4 points

I lile this a lot. This reminds me a lot of KQL (a microsoft query language that’s used for a bunch if azure logging).

I use a lot of python pandas/dask- I’ve definitely got used to viewing a table as a series of operations to perform rather than the kind of declarative queries you get in SQL.

At what point is it no longer SQL? If we’re changing fundamental stuff, I’d love a way of writing loops or if statements that isn’t painful too.

permalink
report
reply
7 points

Stored Procedures have been a thing for literally decades. But they’re an absolute pain.

What would really improve the usefulness of databases are autoindexes and generally more “let me handle that for you”. I’d argue 90% of business apps essentially need a way to store objects and their relationships, but doing that in an efficient manner is really hard (at least if you’ve got a few more rows to handle).

permalink
report
parent
reply
4 points

SQL has pretty powerful conditional support support already and lateral joins are essentially loops if you’re unfamiliar with them.

permalink
report
parent
reply
3 points

I’m not sure I’m convinced by their reasons for not creating a new language (i.e. PRQL). I used it a bit and it was fantastic. It has support for using raw SQL if you need to access really niche features.

Really the only problem is that it doesn’t support mutation, or database-specific features (but you can use the raw SQL escape hatch in that case).

Still, this does look like a great improvement.

permalink
report
reply

Programming

!programming@programming.dev

Create post

Welcome to the main community in programming.dev! Feel free to post anything relating to programming here!

Cross posting is strongly encouraged in the instance. If you feel your post or another person’s post makes sense in another community cross post into it.

Hope you enjoy the instance!

Rules

Rules

  • Follow the programming.dev instance rules
  • Keep content related to programming in some way
  • If you’re posting long videos try to add in some form of tldr for those who don’t want to watch videos

Wormhole

Follow the wormhole through a path of communities !webdev@programming.dev



Community stats

  • 3K

    Monthly active users

  • 1.7K

    Posts

  • 28K

    Comments