Redefine query
Redefine queries are used to modify existing types, type interfaces, or functions in the schema.
Syntax
Redefine queries start with the redefine
keyword following by a single definition statement of the define queries format.
redefine
<definition_statement>
Behavior
Redefine queries can be used to modify types and type interfaces or to override functions.
For clarity and precision, only one redefinition is allowed per query.
An error is returned (on execution or on commit), and no changes are preserved, if:
-
There is no existing definition to redefine.
-
The redefinition matches the definition and does nothing.
-
There are multiple changes in the schema in the result of the redefinition.
-
The query results in an invalid schema.
Statements
-
relates
statements redefine role types specialization usingrelates … as
. -
value
statements redefine value types of attribute types. -
sub
statements redefine supertypes of types. -
@annotations redefine annotations with arguments, replacing their values.
-
fun
statements redefine functions, replacing their interfaces and bodies.
Examples
Schema for the following examples
#!test[schema, commit]
define
entity content owns id;
entity page sub content,
owns page-id,
owns name;
entity profile sub page,
owns username;
entity user sub profile,
owns phone,
owns karma;
attribute id value string;
attribute page-id sub id;
attribute username sub page-id;
attribute name value string;
attribute phone value string;
attribute karma value double;
attribute bio value string;
attribute profile-picture value string;
attribute email @independent, value string @regex("^.*@.*\.com");
user owns bio, owns profile-picture;
attribute tag value string;
entity post owns tag @card(0..);
relation parentship relates parent, relates child;
relation fathership sub parentship, relates father as child;
Redefining types' interfaces and annotations
#!test[schema]
redefine user sub page;
#!test[schema]
redefine karma value integer;
#!test[schema]
redefine email value string @regex("^.*@typedb\.com$");
#!test[schema]
redefine post owns tag @card(0..5);
#!test[schema]
redefine fathership relates father as parent;