SQL Has Problems. We Can Fix Them: Pipe Syntax In SQL
This paper was published by Google recently and it caught my interest as it discussed about SQL.
Crux of the paper: Modify the syntax so operator order matches the semantic evaluation order.
This paper talks about the greatness of SQL, how irreplaceable it has been for the past 50 years, and no language has been so successful enough to displace it,(I’m grinning) and also a few disadvantages of SQL, where I get a bit defensive.. :D
As it is not easy to come up with a new language while keeping the good properties of SQL and also have better syntax, so Google decided to enhance the syntax feature by matching the operator and evaluation order, while retaining the greatness of SQL.
This is the Pipe Syntax symbol |> that Google has come up with.
This is not to confuse with this pipe operator | since bitwise operator in SQL and pipe operations in Linux use it. The reason to choose this symbol is because pipe in Linux world is very common and useful.
Below is an example of how a SQL Pipe syntax would look like compared to a regular T-SQL syntax.
SQL Syntax
SELECT id,
COUNT(*)
FROM table1
WHERE name = 'ABC'
AND title IN ( 'A1', 'A2' )
GROUP BY id
ORDER BY id DESC;
Syntax with Pipe:
FROM table1
|> WHERE
name = 'ABC'
AND title IN ('A1', 'A2')
|> AGGREGATE COUNT(*)
GROUP AND ORDER BY id DESC;
And there are more operators that have been explained in detail in the publication. Link below in Resources tab. With the query above, I wanted to show you an easy example of how piping looks like for a basic T-SQL query. As of now, Pipe syntax is implemented in GoogleSQL and ZetaSQL.
Additionally, I felt there was a lot of repetition about SQL and its behavior in this paper, it could have been compact.
Conclusion: Pipe syntax is definitely easier to understand which order SQL engine follows without having to recall.
But is this something I’m looking forward to implementing ? Definitely NOT at this point of time. I’ve many more impactful things to learn and improve compared to the syntax change and its impact on the systems.
Although the effort behind the initiative taken to enhance the syntax, which Google deems as a disadvantage, is much appreciated.
Resources: https://research.google/pubs/sql-has-problems-we-can-fix-them-pipe-syntax-in-sql/