Data Definition Language

Define Query

define <variable patterns>

The define query will add the given variable patterns to the schema.

After execution, it will return a single answer containing bindings for all variables mentioned in the variable patterns.

Undefine Query

undefine <variable patterns>

The undefine query will remove the given variable patterns from the schema.

In order to remove a schema concept entirely, it is sufficient to undefine its direct super-concept:

undefine person sub entity;

Supported Properties

Within the variable patterns of both define and undefine queries, the following properties are supported:

id

$x id <identifier> will assign $x to an existing concept with the given ID. It is an error if no such concept exists.

label

$A label <identifier> will assign $A to a schema concept with the given label. If no such schema concept exists, one will be created.

sub

$A sub $B defines the schema concept $A as the direct sub-concept of the schema concept $B.

relates

$A relates $B define the relationship type $A to directly relate the role $B.

In the case where $B does not have a defined sub, this will also implicitly define $B sub role.

plays

$A plays $B defines the type $A to directly play the role $B.

has (type)

$A has <identifier> defines instances of the type $A to have attributes of the attribute type <identifier>.

has is syntactic sugar for a particular kind of relationship.

This is done using the following relationship structure:

has-<identifier>-owner sub has-<sup>-owner;
has-<identifier>-value sub has-<sup>-value;
has-<identifier> sub has-<sup>, relates has-<identifier>-owner, relates has-<identifier>-value;

$A plays has-<identifier>-owner;
<identifier> plays has-<identifier>-value;

Where <sup> is the direct super-concept of <identifier>.

key (type)

$A key <identifier> defines instances of the type $A to have a key of attribute type <identifier>.

key is syntactic sugar for a particular kind of relationship.

This is done using the following relationship structure:

key-<identifier>-owner sub key-<sup>-owner;
key-<identifier>-value sub key-<sup>-value;
key-<identifier> sub key-<sup>, relates key-<identifier>-owner, relates key-<identifier>-value;

$A plays<<required>> has-<identifier>-owner;
<identifier> plays has-<identifier>-value;

Where <sup> is the direct super-concept of <identifier>. (note that plays<<required>> is not valid syntax, but indicates that instances of the type must play the required role exactly once).

datatype

$A datatype <datatype> defines the attribute type $A to have the specified datatype.

regex

$A regex <regex> defines the attribute type $A to have the specified regex constraint.

is-abstract

$A is-abstract defines the type $A to be abstract.

when

$A when <pattern> defines the rule $A to have the specified when pattern.

then

$A then <pattern> defines the rule $A to have the specified then pattern.

Tags: graql