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"},
}
One view of that relation as a table is:
┌─────────┬───────────┐ │ day_seq │ day_name │ ├─────────┼───────────┤ │ 1 │ Monday │ │ 2 │ Tuesday │ │ 3 │ Wednesday │ │ 4 │ Thursday │ │ 5 │ Friday │ │ 6 │ Saturday │ │ 7 │ Sunday │ └─────────┴───────────┘
Heading
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(Boolean:trueorfalse)int(64 bit integer)float(64 bit floating-point number)str(string)time(date and/or time)tuple{...}(nested tuple){...}(nested relation)
Other types will be discussed or added later.
Body
The body is a set of tuples. A tuple is a set of attribute names and typed values.
For example:
tuple{day_seq:=1, day_name:="Monday"}
Here, the tuple has two attributes: day_seq is assigned the value 1 and day_name is assigned the string "Monday".
Shorthand Syntax for Body Tuples
For convenience, a shorthand syntax allows for specifying the body of the relation using lists of values. This shorthand relies on the left-to-right ordering of the values aligning with the left-to-right ordering of the attributes in the heading.
Here’s the same relation using the shorthand notation:
{day_seq:int, day_name:str}{
[1, "Monday"],
[2, "Tuesday"],
[3, "Wednesday"],
[4, "Thursday"],
[5, "Friday"],
[6, "Saturday"],
[7, "Sunday"],
}
dee and dum
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.