Here is a relation literal. It has two parts, each between braces. It has a heading and a body.
{ day_seq:int, day_name:str}{
tuple{day_seq:=1, day_name:="Monday"},
tuple{day_seq:=2, day_name:="Tuesday"},
tuple{day_seq:=3, day_name:="Wednesday"},
tuple{day_seq:=4, day_name:="Thursday"},
tuple{day_seq:=5, day_name:="Friday"},
tuple{day_seq:=6, day_name:="Saturday"},
tuple{day_seq:=7, day_name:="Sunday"},
}
┌─────────┬───────────┐ │ day_seq │ day_name │ ├─────────┼───────────┤ │ 1 │ Monday │ │ 2 │ Tuesday │ │ 3 │ Wednesday │ │ 4 │ Thursday │ │ 5 │ Friday │ │ 6 │ Saturday │ │ 7 │ Sunday │ └─────────┴───────────┘
The heading is a set of attributes:
day_seq
and
day_name
in the example above. Each attribute has a name and a type. Currently available types include:
bool
(true
/false
)int
(64 bit)float
(64 bit)str
time
tuple{...}
{...}
(i.e. a relation)
The body is a set of tuples. A tuple is a set of attribute names and typed values.
Here's a relation literal with a shorthand for the body tuples to simplify typing. This relies on the left-to-right ordering of the values in square brackets aligning with the left-to-right ordering of the heading, but only for loading the relation from the script: after that is has no left-right ordering.
{month_seq:int, month_name:str}{
[1, "January"],
[2, "February"],
[3, "March"],
[4, "April"],
[5, "May"],
[6, "June"],
[7, "July"],
[8, "August"],
[9, "September"],
[10, "October"],
[11, "November"],
[12, "December"],
}
┌───────────┬────────────┐ │ month_seq │ month_name │ ├───────────┼────────────┤ │ 1 │ January │ │ 2 │ February │ │ 3 │ March │ │ 4 │ April │ │ 5 │ May │ │ 6 │ June │ │ 7 │ July │ │ 8 │ August │ │ 9 │ September │ │ 10 │ October │ │ 11 │ November │ │ 12 │ December │ └───────────┴────────────┘
There are two pre-defined relations named
dee
and
dum
which are the ones with no attributes:
dee
has one tuple,
dum
has none.
dee
┌┐ ││ ├┤ ││ └┘
dum
┌┐ ││ ├┤ └┘
Later we'll see how we can use
dee
in another shorthand to construct single-tuple relations.