News for hackers. Stuff that matters.
Re:We Can Do Better Than SQL by tathougies on Thursday May 09, 2019 @03:21PM (#19871344)
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.

Re:We Can Do Better Than SQL by dragonwriter on Thursday May 09, 2019 @05:40PM (#19872705)
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.

Re:We Can Do Better Than SQL by vpetrovykh on Thursday May 09, 2019 @07:54PM (#19873707)
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.
Re:We Can Do Better Than SQL by RedCrowbar on Thursday May 09, 2019 @03:28PM (#19871430)
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:

  SELECT (SELECT count(*) FROM table) + 1
This is not:

  SELECT (SELECT * FROM table), 1
In EdgeQL:

  SELECT (count(SomeType) + 1)
and

  SELECT (SomeType, 1)
are equally valid.
Re:We Can Do Better Than SQL by Svip on Thursday May 09, 2019 @03:37PM (#19871509)
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:

    SELECT count(*) + 1 FROM table
And

    SELECT *, 1 FROM table
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:

    SELECT (SELECT * FROM table) + 1
Not valid... unless `table` only had one row and one column containing a number.
Re:We Can Do Better Than SQL by RedCrowbar on Thursday May 09, 2019 @03:40PM (#19871532)
Yes, and that's actually the point being made in the post. You need to rewrite your queries to make SQL happy.
Re:We Can Do Better Than SQL by tathougies on Thursday May 09, 2019 @03:53PM (#19871693)
The EdgeQL query has no obvious meaning, unless (,) calculates the cross product. Saying

SELECT Table1, 1

returns each row of Table1 along with 1 and that 1 returns the set {1} means that you have arbitrarily assigned each row of Table1 a row from the set {1}. This gives what you want in the case of a scalar, but what about a non-scalar.

For example, suppose Table1 contains (John, Smith), (Alice, Perkins), (Bob, Best). Then, what should

SELECT Table1, {1,2}

return? If you do not say cross product, you have arbitrarily assigned rows to one another, resulting in meaningless data. If you say cross product, then you have rewritten the sql expression

SELECT * FROM Table1, (VALUES (1), (2))

I don't disagree the SQL syntax is longer and has some unnecessary keywords, but unlike EdgeQL, the query means something particular.

Re:We Can Do Better Than SQL by RedCrowbar on Thursday May 09, 2019 @04:06PM (#19871843)
In EdgeQL, expressions are element-wise functions over the cross-product of the input sets:

    edgedb> SELECT {'First', 'Second'} ++ '!';
    {'First!', 'Second!'}
EdgeQL queries are essentially set comprehensions.
Re:We Can Do Better Than SQL by tathougies on Thursday May 09, 2019 @04:19PM (#19871988)
Right, so SELECT Table1 and SELECT 1 compose to SELECT Table1, 1 in the same way that

SELECT 1

and SELECT * FROM TABLE1 and SELECT 1 compose to

> SELECT * FROM TABLE1, (SELECT 1)

Aside from the different syntax, it is the same kind of composition. Not sure what EdgeQL has gained here, then.

Re:We Can Do Better Than SQL by theclaw on Friday May 10, 2019 @03:31AM (#19875838)
Erm, isn’t the syntax the whole point of this discussion?
Re:We Can Do Better Than SQL by notimetorelax on Thursday May 09, 2019 @03:45PM (#19871601)
Is this such a common problem that you need a new language to solve it?
Re:We Can Do Better Than SQL by 1st1 on Thursday May 09, 2019 @03:51PM (#19871674)
We think that people struggling with writing good/advanced SQL queries and the existence of ORMs and other heavy frameworks to make RDBMSes "friendly" is a serious problem. And inventing a a new querying language is a necessary step to make relational databases more accessible.
Re:We Can Do Better Than SQL by munk-a on Thursday May 09, 2019 @04:30PM (#19872115)
Just to clarify (and I strongly dislike overuse of ORMs)...

Some people use a thing x

A subset of those people use a subset of x called y

This subset of people have built a tool to make y easier to express

Thus x is invalid

I think that's a really bad argument, if everyone was using ORMs then we'd all merrily forget about SQL and just use ORMs which would become the new "language for structuring queries", but we don't all, and EdgeDB in particular thinks that ORMs provide a much degraded expression set from SQL and thus want to tweak X so that it's as expressible as the tool to express Y but without making it just about Y... I think your goal boils down to shifting the trade-off point between X and Y - the extreme of which is writing a very expressive Y that also supports X but in a non-expressive manner.

Re:We Can Do Better Than SQL by tathougies on Thursday May 09, 2019 @03:50PM (#19871657)
> 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.

Re:We Can Do Better Than SQL by RedCrowbar on Thursday May 09, 2019 @03:57PM (#19871744)
`(a, b)` is a cross-product, just like "SELECT * FROM a, b"
Re:We Can Do Better Than SQL by thwd on Thursday May 09, 2019 @04:08PM (#19871864)
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.

Re:We Can Do Better Than SQL by tqi on Thursday May 09, 2019 @05:32PM (#19872655)
> SELECT (SELECT * FROM table), 1

What would you expect to returned for by this query?