News for hackers. Stuff that matters.
Re:Things I wished more developers knew about databases by Viliam1234 on Wednesday April 22, 2020 @03:14PM (#22949110)
Reading SQL is like reading German, where the last word in a long sentence determines the meaning of the entire sentence.

An SQL statement starts with "select ABC.XYZ", but you have no idea what it means, because only one screen later it is written that "ABC" is actually an alias for "T_ACCOUNT_BUSINESS_CREDITS" or something. The logical order would be "from ... where ... select ...".

Imagine a programming language designed like SQL. It would look approximately like this:

  function foo(a) {
    return s;
    b = join(a);
    s = concatenate("[", b, "]");
    by the way, a is list of strings, b is string, s is string;
    also, function "join" is imported from "lists", and "concatenate" is imported from "string" module;
    actually, don't return the result, just tell me how many characters it would have;
  }
Re:Things I wished more developers knew about databases by karmakaze on Wednesday April 22, 2020 @09:17PM (#22951877)
I don't know why people think this. After much thought, it's because they read chronologically which isn't how SQL works. It doesn't 'execute' in the written sequence.

The entire statement is a logical one like a mathematical equation. You wouldn't think that the meaning of (a + b) * (c + d) implies that (a + b) has to be done first. Maybe in some computer languages it may like early C compilers.

Given that: "select ABC.XYZ" is perfectly well formed, it's like a forward reference declaration where ABC is the alias for a table-like thing and XYZ is the alias for the column-like thing. I mostly read my SQL inside-out, starting with uncorrelated subqueries.

Another pet peeve: using the keyword INNER or OUTER is just noise.

Re:Things I wished more developers knew about databases by Izkata on Thursday April 23, 2020 @01:11AM (#22953014)
> Imagine a programming language designed like SQL.

Okay:

  const { ABC, XYZ } = source_table.get(id = 5);
Oh, wait...