-
Notifications
You must be signed in to change notification settings - Fork 15
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
Join #72
Comments
Oops. We can't have
I now think we should allow
|
Iterating again. Let's make And the syntax for
|
Fixed in ab10217. This time we support inner join (the |
Add clauses to
from
to support inner and outer joins. Allow allow cross joins (comma syntax) at any position in thefrom
clause, not just at the start.We currently support cross join via comma syntax:
Technically, comma join is a cross join (cartesian join) because it does not allow a condition. We add several new types of join:
join
is an inner joinleft join
is a left outer join, with optional rows on the rightright join
is a right outer join, with optional rows on the leftfull join
is a full outer join, with optional rows on the left and rightAll of these are followed by
on
and a boolean condition. For example,In the first example, note that the two 'scans' occur before other clauses (
where
). After this change we will still allow comma syntax, but also after other clauses:where
and,
have the same precedence and are left-associative, so the secondwhere
applies tofrom e in emps where e.job = "CLERK", d in depts
, not justdepts
.If you want to filter just
depts
, use a parenthesizedfrom
expression:These precedence and associativity are different from SQL. In SQL,
,
has lower precedence thanJOIN
, soSELECT ... FROM a CROSS JOIN b, c CROSS JOIN d
becomes the expression tree "(a . b) . (c. d)". But in Morel,from a in as, b in bs join c in cs on true, d in ds
becomes the expression tree "((a . b) . c) . d".In SQL, the various kinds of outer join invent 'outer' rows whose column values are all null. Morel does not have null, so instead wraps rows in
Option
:This query is
right join
, and therefore the rows on the left side (e
) become optional. Inleft join
, rows on the right become optional, and infull join
rows on both sides become optional.Note that Morel prints
d
beforee
, because fields are in alphabetical order. Bute
is considered to be the left input to the join, because it occurs earlier in thefrom
expression, andd
is the right input. The variable name is irrelevant.There is no equivalent of SQL's
USING
clause.There is no syntax for left, right or full cartesian join, but you can achieve the same effect by writing
on true
:The text was updated successfully, but these errors were encountered: