Data

Tuple Extraction

Since relations are comprised of tuples, we can extract a tuple from a relation, providing it has only 1 tuple in it. The print function displays the tuple horizontally on the console.

print(S[STATUS=10].tuple)
┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄
  SNO   SNAME   STATUS   CITY   
  S2    Jones       10   Paris  
┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄┄

And we can go the other way: given a tuple, we have a shorthand to create a relation from it: to_rel().

to_rel(tuple{SNO:="S2", SNAME:="Jones", STATUS:=10, CITY:="Paris"})
SNOSNAMESTATUSCITY
S2Jones10Paris

We can compare tuples with other tuples, such as tuple literals, again using =.

S[STATUS=10].tuple = tuple{SNO:="S2", SNAME:="Jones", STATUS:=10, CITY:="Paris"}
true

And we can check whether a tuple is a member of a relation using <=. Or using (if your keyboard can create it).

S[STATUS=10].tuple <= S
true
S[STATUS=10].tuple ∈ S
true

There is also a >= operator to check whether a relation contains a tuple (or ).

We can extract an attribute from a single-tuple relation using .tuple.name, e.g.

S[STATUS=10]{CITY}.tuple.CITY
Paris

Given a single-tuple relation with a single attribute, we can extract that attribute using .tuple.* or the shorthand ..

S[STATUS=10]{CITY}.tuple.*
Paris
S[STATUS=10]{CITY}..
Paris

Generally, tuple extraction should be avoided or left until the final presentation layer: working with relations affords more flexibility to combine data without having to check for the special case of exactly 1 tuple.