TypeDB 3.0 is live! Get started for free.

Redefine query

Redefine queries are used to modify existing types, type traits, 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 traits 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

Examples

Redefining types' traits and annotations

Redefining type’s sub
redefine user sub page;
Redefining attribute type’s value type
redefine karma value integer;
Redefining value type’s annotation with arguments
redefine email value string @regex("^.*@typedb\.com$");
Redefining type trait’s annotation with arguments
redefine redefine post owns tag @card(0..5);
Redefining relates specialization
redefine fathership relates father as parent;

Redefining functions

Everything except for the function name can be redefined using redefine queries.

redefine
  fun karma_with_squared_value($karma: karma) -> double:
    match
      let $karma-squared = $karma * $karma;
    return first $karma-squared;