Comment by tathougies
7 years ago
The article criticized SQL because the following expressions are incompatible
> SELECT * FROM table
and
> SELECT count(*) FROM table
This is actually not true, as both return table values. It then says that, in EdgeQL, every expression results in a 'set'. This is a distinction without a difference.
I don't disagree we can do better, but this is the same.
It's only a slight misstatement; scalar queries are a subset of table queries in SQL, rather than different thing, but scalar queries are allowed in places where other table queries are not.
The difference in EdgeDB isn't really everything returns a set, but seems instead to be that everything consumes sets and not just scalars.
You are exactly right about everything consuming sets in EdgeDB. Even when a function is defined on scalars, it's really defined on singleton sets. Literals are also singleton sets, so "1" and "{1}" are equivalent and so are "foo(1)" and "foo({1})". Usually we omit the set braces for singleton values to reduce visual noise.
There is a difference. You are right in a sense that scalar expressions are a form of a table expression, but...
This is a valid expression:
This is not:
In EdgeQL:
and
are equally valid.
The brackets make it look like they are both subqueries and contained within in the EdgeQL examples. As such, you could write the examples in SQL like this:
And
Both of which are valid in SQL. And you'd get the same result as in the EdgeQL examples.
Indeed, a more relevant second counter example would be:
Not valid... unless `table` only had one row and one column containing a number.
Yes, and that's actually the point being made in the post. You need to rewrite your queries to make SQL happy.
7 replies →
> SELECT (SomeType, 1)
This cannot be the case if you call each thing a 'set'. Unless `(a, b)` calculates the cross product, there is no meaningful non-arbitrary way to assign each element of a to an element of b. That would depend on an ordering, which makes it not a set to everyone but a marketing dept somewhere.
`(a, b)` is a cross-product, just like "SELECT * FROM a, b"
They're saying that both of those expressions are valid, not equivalent.
SELECT count(star) FROM table
and
SELECT star FROM table
Are both valid, not equivalent.
Furthermore, listing any kind of set depends on some ordering, be it random.
> SELECT (SELECT * FROM table), 1
What would you expect to returned for by this query?