Page 1 of 1

JOIN alternative for partial data?

Posted: Sat Nov 10, 2018 3:28 am
by asulling

I am new here and still struggling with the big picture, sorry:

Does Tutorial D support a more compact alternative than the example below to the SQL "X left join Y" clause where in the relational domain missing data from Y joined with tuples of X would be marked by (alternatively put: grouped as) an empty new relation Z, and tuples from y in the result would be similarly grouped as relation Z?

If not then what is the Tutorial D philosophy behind not quite supporting such a frequently needed alternative of retrieving highly cohesive data preferably in one operation? What is the Tutorial D approach to retrieving e.g. a list of all persons with phones attached to those associated with at least one?

Code: Select all

VAR phone REAL RELATION {number INTEGER, owner CHARACTER} KEY {number};
CONSTRAINT phone_fkey_person phone { owner } RENAME { owner AS name } <= person { name };
person := RELATION {
    TUPLE {name 'Jack'},
    TUPLE {name 'Jill'},
    TUPLE {name 'Jane'}
phone := RELATION {
    TUPLE {owner 'Jack', number 123},
    TUPLE {owner 'Jane', number 456},
    TUPLE {owner 'Jane', number 789}
tmp := person RENAME {name AS j} SEMIJOIN ( phone RENAME {owner AS j} ) RENAME {j AS name};
tmp := person MINUS tmp;
VAR leftjoin REAL RELATION {name CHARACTER, phones RELATION {number INTEGER}} KEY {name};
leftjoin := EXTEND tmp : {phones := RELATION {number INTEGER} {}};
leftjoin := leftjoin UNION ( person RENAME {name AS j} JOIN ( phone RENAME {owner AS j} ) GROUP {number} AS phones RENAME {j AS name} );

Re: JOIN alternative for partial data?

Posted: Tue Nov 13, 2018 9:39 am
by Dave
As this is a relatively broad question about Tutorial D in general rather than Rel in particular, I encourage you to join the TTM Forum at and ask your question there.