Officially out now: The TypeDB 3.0 Roadmap >>

Statements

This reference covers the usage of statements in TypeQL.

A TypeQL statement is a building block of a TypeQL pattern. Statements in TypeQL are always end with a semicolon.

Simple statements

A simple statement is the smallest pattern that can be in a TyepQL query.

Most simple statements have two or three parts: <PREDICATE> <SUBJECT>, <SUBJECT> <PREDICATE> or <SUBJECT> <PREDICATE> <OBJECT>, where <PREDICATE> is a TypeQL keyword. However, there can be other more complex statements like let …​ in statement.

Composite statements

Multiple simple statements with the same subject can be combined into a composite statement. A composite statement starts with a single subject, and multiple comma-separated simple statements with subject omitted.

See an example
Composite statement example
define
  entity user sub profile,
    owns phone,
    owns karma,
    plays parentship:parent,
    plays parentship:child;

The above example combines simple entity, sub, owns, and plays statements to the same result without repeating the subject:

Equal simple statements example
define
  entity user;
  user sub profile;
  user owns phone;
  user owns karma;
  user plays parentship:parent;
  user plays parentship:child;

The comma separation is required before a <PREDICATE> if its <SUBJECT> already has another <PREDICATE> on its right side.

The first two predicates in the example above do not require a comma. However, every simple statement can be separated by commas if preferred.

Definition statements

Definition statements do not contain variables. Most definition statements can also be used as pattern statements.

Type definitions

Entity definitions

Used to define a new entity type.

Relation definitions

Used to define a new relation type.

Used to define a new role for a relation type.

Attribute definitions

Used to define a new attribute type.

Used to define the value type of an attribute type.

Struct definitions

Coming soon

Trait definitions

Used to define a new roleplayer for a role.

Used to define a new owner of an attribute type.

Subtyping definitions

Used to define an alias label for a type.

Function definitions

Used to define a function.

Type alias definitions

Used to define an alias label for a type.

Pattern statements

Pattern statements are statements that contain variables. Most definition statements can also be used as pattern statements, and will not be repeated in this section (see pages above for their pattern usage).

Typing statements

Used to specify the type of a data instance.

Used to specify the roleplayers in a relation.

Used to specify an attribute of an entity or relation.

Assignments

Used to assign the result of an expression to a variable.

Used to assign a stream or list element to a variable.

Comparisons

Used to specify that two variables represent the same data instance.

Used to specify that a stream or list contains a data instance.

Used to specify that a string matches a specified regex pattern

Data identity statements

Used to identify a type by its label.

Used to identify a data instance by its internal ID.