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.

    • Kissaki@programming.dev
      link
      fedilink
      English
      arrow-up
      8
      ·
      edit-2
      3 months ago

      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.

    • MajorHavoc@programming.dev
      link
      fedilink
      arrow-up
      6
      arrow-down
      5
      ·
      3 months ago

      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!

  • atzanteol@sh.itjust.works
    link
    fedilink
    English
    arrow-up
    8
    arrow-down
    1
    ·
    3 months ago

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

        • frezik@midwest.social
          link
          fedilink
          arrow-up
          2
          arrow-down
          1
          ·
          3 months ago

          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.

          • Kogasa@programming.dev
            link
            fedilink
            arrow-up
            4
            ·
            3 months ago

            This should be done with font ligatures, not replacing character combinations with other characters that can’t be typed normally

          • xmunk@sh.itjust.works
            link
            fedilink
            arrow-up
            4
            ·
            3 months ago

            I think that makes it harder to work in a language… you certainly can set up an editor autoreplacement but once a decade or so someone’s going to need to hotfix something in a strange environment and trying to force things into nano using alt codes is a real pain.

            That said the intentionally hard to type symbols with ascii replacements actually make me less sad than things like this syntax that requires a pipe character… I don’t know if you’re a polyglot (or ever typed on a keyboard in quebec) but most of these languages’ symbol choices are convenient on an en-US keyboard with little consideration for international keyboard layouts and there are a lot of hard to type symbols on the spanish keyboard that are very common in programming languages.

    • anti-idpol action@programming.dev
      link
      fedilink
      arrow-up
      1
      ·
      edit-2
      3 months ago

      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})
      
  • xmunk@sh.itjust.works
    link
    fedilink
    arrow-up
    8
    arrow-down
    3
    ·
    3 months ago

    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.

      • xmunk@sh.itjust.works
        link
        fedilink
        arrow-up
        2
        ·
        3 months ago

        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.

        • frezik@midwest.social
          link
          fedilink
          arrow-up
          2
          ·
          edit-2
          3 months ago

          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.

  • houseofleft@slrpnk.net
    link
    fedilink
    English
    arrow-up
    4
    ·
    3 months ago

    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.

    • leisesprecher@feddit.org
      link
      fedilink
      arrow-up
      7
      ·
      3 months ago

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

    • xmunk@sh.itjust.works
      link
      fedilink
      arrow-up
      3
      ·
      3 months ago

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

  • FizzyOrange@programming.dev
    link
    fedilink
    arrow-up
    3
    ·
    3 months ago

    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.

  • Kissaki@programming.dev
    link
    fedilink
    English
    arrow-up
    2
    arrow-down
    3
    ·
    edit-2
    3 months ago

    Any query can have zero or more pipe operators as a suffix, delin-
    eated with the pipe character “|>”.

    “delineated”? Looks like a typo of delimited?

    Or is that a play on neat and delimited?