Views are a degenerate, second-class form of query abstraction, as are common table expressions and the numerous other features added to SQL over the years to paper over the lack of proper first-class query abstractions.
It's like saying a programming language doesn't need first-class functions because we have disjoint unions and we can perform defunctionalization by hand. Strictly true, but really missing the point.
When viewed through the lens of general purpose imperative or functional programming languages, it's easy to see how it can be seen as falling short.
I'll admit much of the tooling and driver APIs leave a lot to be desired.
Some tools do make good efforts though such as nested fragments in this driver.
It's still lacking even then. You can't assign a set to variable for instance, and then use that variable in other definitions.
record[]
some_table_name[]
jsonb containing an array of records
And of course the most obvious shared set variable of all, supported by every popular RDBMS in existence: the temporary table. Something scoped to the current session, of essentially unlimited width and length, and accessible to other definitions and queries.We get it. You want something closer to a general purpose programming language. But don't confuse your preferences with actual missing features.
I actually don't want a general purpose programming language as that's not suitable for data access, I just want a query language that doesn't impose artificial limitations on relations.
Edit: although I will admit that programming language theory is a hobby, so that's why I understand the source of the pain every time I have to use SQL. LINQ almost gets this right, but is still a huge improvement on SQL.
unnest support is potentially on the horizon for EF core for PG [2], but already supported for Couchbase [3].
[1] https://learn.microsoft.com/en-ca/ef/core/what-is-new/ef-cor...
[2] https://github.com/npgsql/efcore.pg/issues/1525
[3] https://github.com/couchbaselabs/Linq2Couchbase/blob/master/...
I strongly think we should have the best examples of SQL to compare against. I've ironically made this complaint for other libraries, so I'm alarmed that folks think we might have done the same.
We would take a PR for the first example if folks think that's better spacing. (I think the spacing is the only difference?)
For the second — `USING` isn't fully equivalent to `ON`. There are discussions on GH (https://github.com/PRQL/prql/issues/723) as to which we should compile to. In the meantime, we'd take a PR on anything that is equivalent.
In terms of portability because its not supported by, e.g., MSSQL, sure.
In terms of its semantics, though:
t1 [LEFT/RIGHT/INNER] JOIN t2 USING col
Is fully equivalent to: t1 [LEFT/RIGHT/INNER] JOIN t2 ON (t1.col == t2.col)
So for a comparison to SQL as used by most RDBMSs (rather than MSSQL specifically), rather than “what should PRQL compile to”, USING is quite appropriate.It may be that the intent of the homepage pairing is to highlight the actual compilation result and not provide a comparison to SQL-as-it-would-manually-be-written, but the presentation doesn’t make it clear that that’s the purpose.
To take one point from there:
> Is fully equivalent to:
They're not fully equivalent — `USING` combines the two columns into a single column, `ON` doesn't.
The person you are responding to is likely in this cohort. You're correct that they aren't exactly equivalent, but that's an artifact of your table definition, not the language. It likely seemed perfectly reasonable to the commenter that this naming was a trivial detail in the scope of the greater conversation.
WITH t AS (SELECT 1 x)
SELECT x FROM t JOIN t u ...;
That breaks if you fill in the ... with "ON t.x = u.x" because there are two columns called "x", but works with "USING (x)" because they get collapsed into a single column. I think it makes sense to say those aren't fully equivalent."We'd take a PR" is a great line for someone who's already sold on the concept, but it's not super helpful for flaws in your marketing. Reading OP, it doesn't sound like they trust you enough to find it to be worth their time fixing your examples for you.
Though I'm not sure how to find consensus on what is the best representation of SQL without asking folks to make a reviewable suggestion.
I had thought the examples are currently in their clearest state — I definitely don't think it's obvious that bunching lines up makes things look better.
But I wanted about this the last time PRQL was submitted in its own right - https://news.ycombinator.com/item?id=36869376 - so I'll leave it there!
They style it as "4 lines vs 10 lines!" when it's actually 4 lines vs 4 lines.
The join example is similarly deceptive: Nonsense.