Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add union, intersect, minus operators #30

Closed
julianhyde opened this issue Apr 22, 2020 · 1 comment
Closed

Add union, intersect, minus operators #30

julianhyde opened this issue Apr 22, 2020 · 1 comment

Comments

@julianhyde
Copy link
Collaborator

julianhyde commented Apr 22, 2020

Add union, intersect, minus query operators.

Example 1:

(from e in scott.depts yield e.deptno)
except
(from d in scott.depts yield d.deptno)

Example 2:

from deptno in (
 (from e in scott.depts yield e.deptno)
 union
 (from d in scott.depts yield d.deptno))
group compute sum of deptno

Should these operators eliminate duplicates? Most convenient would be if union did not eliminate duplicates (like SQL UNION ALL), effectively treating left and right sides as lists, and if intersect and except treated left side as a list and right side as a set (somewhat like SQL INTERSECT ALL and EXCEPT ALL).

If people want to eliminate duplicates afterwards, they can enclose in from x in (...) group x.

@julianhyde
Copy link
Collaborator Author

julianhyde commented Apr 25, 2020

union and except have the same precedence as + and -; intersect has the same precedence as *. This is consistent with SQL (although the SQL set operators never apply to scalar expressions).

The precedence is higher than in SQL, which means that occasionally you use parentheses where you would not in SQL. In particular, the case from ... yield union from ....

These are more 'list' operators than 'set' operators:

  • union acts like SQL UNION ALL, preserving duplicates on both sides;
  • intersect and except preserve duplicates on the left side, but unlike SQL INTERSECT ALL and EXCEPT ALL they keep/remove every occurrence of an element on the left side if there are any occurrences of the element on the right side.

In relational.sml, I added some examples that simulate SQL's INTERSECT ALL, EXCEPT DISTINCT, etc.

Fixed in 8aa40be.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant