News for hackers. Stuff that matters.
Re:Relational is more than SQL by maximilianroos on Saturday September 16, 2023 @07:03PM (#37539692)
Quoting from https://www.scattered-thoughts.net/writing/against-sql/:

---

There are many cases where a small change to a computation requires totally changing the structure of the query, but subqueries are my favourite because they're the most obvious way to express many queries and yet also provide so many cliffs to fall off.

    -- for each manager, find their employee with the highest salary
    > select
    >   manager.name,
    >   (select employee.name
    >    from employee
    >    where employee.manager = manager.name
    >    order by employee.salary desc
    >    limit 1)
    > from manager;
     name  | name
    -------+------
     alice | bob
---

If the inner query has more than one row, the query will raise an error. That's difficult to know from the SQL alone.

Re:Relational is more than SQL by lolinder on Sunday September 17, 2023 @01:03PM (#37547171)
Difficult for the author, but not for static analysis. A static analysis system can pretty easily enforce that `limit 1` be set when a query is used in that position.