The input script consists of several blocks separated by empty lines. The first token of the block identifies its type.
Supported block types: section, comment, data, print-ra, set-ra, print-sql, set-sql. run-sql, sql-save, sql-restore, print-dl, set-dl,
Lines starting with '#
' are ignored.
The output of the script may be used as its input, producing the same result. This could be used for pretty-printing and normalization.
The section
block separates logical parts of the input script.
The section copies its content to the output and decorates it with lines consisting of '#
's.
The comment
block defines text comment.
Comment copies its content to the output without further processing.
The data
block defines a relation.
The first line of the data block contains a relation's name (identifier). The second line contains a comma-separated list of attributes (also identifiers). The following lines contain one tuple each. A tuple is a comma-separated list of values.
Supported value types:
'
), may contain commas and newlines.If there is a relation with the same name, it is replaced by the new one.
The data block normalizes its contents and copies it to the output.
The print-ra
outputs the result of the relational algebra expression.
This block copies normalized relational algebra expression to the output. The expression evaluation result follows.
Supported operations:
Relation reference by name (identifier).
Unary operations.
A unary operation has two arguments. The first argument is operation-dependent and comes in curly braces. The second one is the sole operand of the operation. It comes in parentheses.
π
', 'pi
', 'proj
', 'projection
', 'p
')
first argument is a comma-separated list of attributes to project to.
σ
', 'sigma
', 'selection
', 'select
', 'sel
', 's
')
first argument is the selection condition (see below).
ρ
', 'rho
', 'rename
', 'ren
', 'r
')
first argument is a comma-separated list of attribute renames.
Rename consists of a new attribute name (identifier), the equals sign ('=
'),
and an old attribute name (identifier).
Binary operations:
∖
', 'difference
', 'diff
', 'except
').
⋃
', 'union
');
⋂
', 'intersection
')
⋈
', 'njoin
', 'natjoin
', 'natural-join
', 'nj
');
×
', 'cjoin
', 'cartjoin
', 'cartesian-join
', 'cj
');
⟕
', 'ljoin
', 'left-join
', 'lj
');
⟖
', 'rjoin
', 'right-join
', 'rj
');
⟗
', 'ojoin
', 'outer-join
', 'fjoin
', 'full-join
', 'fj
', 'oj
');
⋉
', 'lsemi
', 'left-semijoin
', 'lsj
');
⋊
', 'rsemi
', 'right-semijoin
', 'rsj
');
÷
', 'div
', 'division
', 'sd
');
⋇
', 'gdiv
', 'great-division
', 'gd
');
Priorities: difference (lowest), union, intersection, other binary operations, unary operations, and expression in parentheses.
Supported subexpressions for selection operations:
Attribute reference (identifier).
Literals: integers and quoted strings.
Unary functions:
length
');not
').Binary operations (in decreasing priority order):
⋀
', '&&
');⋁
', '||
');=
'), inequality ('≠
', '<>
'),
less ('<
'), less-or-equal ('≤
', '<=
'),
greater ('>
'), greater-or-equal ('≥
', '>=
');
+
') and subtraction ('-
');*
') and division ('/
').
The set-ra
defines a relation based on the result of the relational algebra expression.
It consists of the relation's name (identifier), and the expression,
separated by the equals sign ('=
').
If there is a relation with the same name, it is replaced by the new one.
This block copies normalized relational algebra expression to the output. The expression evaluation result follows.
select
statement
The print-sql
outputs the result of the SQL select
statement
as a relation.
SQL support is provided by sql.js
– SQLite compiled to JavaScript.
All defined relations are accessible for SQL queries as tables having
one column for each relation's attribute. The columns type is char
.
This block copies select
statement to the output.
The statement evaluation result follows.
select
statement
The set-sql
defines a relation based on the result of
the SQL select
statement.
It consists of the relation name (identifier), and the select
statement,
separated by the equals sign ('=
').
If there is a relation with the same name, it is replaced by the new one.
The sql.js does not provide
column information for empty (zero records) results.
In this case the empty result the relation will contain a sole EmptyTable
attribute.
This block copies the select
statement to the output.
The statement evaluation result follows.
The run-sql
executes specified DDL or DML statement.
This block copies the statement to the output.
The sql-save
saves current SQLite state under provided identifier.
The sql-restores
SQLite state saved under provided identifier.
The print-dl
outputs the result of a Datalog query.
The Datalog query consists of one or more relation definitions. The result of the query is the last relation.
The relation definition consists of one or more rules. The first rule defines the relation's attribute names. Following rules may use the same or different attribute names.
Each rule has a form
Name(
Attr1,
Attr2,
...,
Attrn)
:-
Atom1,
Atom2,
...,
Atomm.
Where Name – relation's name, Attri – relation attribute names, Atomi – rule atoms. The rule may use only attributes defined by relational atoms.
There are three types of atoms:
NameWhere Name – relation name, Valuei – value to test. The value may be either an attribute, a constant, or a variable reference ((
Value1,
Value2,
...,
Valuen)
:Var
).
The relational atom defines all specified attributes.
Every attribute used by the negative relational atom should be declared by the preceding relational atom. '¬
Name(
Value1,
Value2,
...,
Valuen)
not
' may substitute ¬
for the sake of easy input.
This block copies the Datalog query to the output. The query result follows.
The set-dl
block defines a relation based on the result of
the Datalog query.
It consists of the relation's name (identifier), and the Datalog query,
separated by the equals sign ('=
').
If there is a relation with the same name, it is replaced by the new one.
This block copies the query to the output. The statement evaluation result follows.