TypeDB 3.0 is live! Get started for free.

Update stage

An update stage updates data in the database. Updatable data includes ownerships of attributes and role players of relations.

Syntax

The body of an update stage is a sequence of update statements, which are similar to has and links statements of insert.

update <update-statement> [ <update-statement> ... ]

Behavior

  • Has statements replace existing attribute ownerships of the specified attribute’s type (isa!) with a new ownership of the specified instance. If an attribute is provided by value, the attribute type is mandatory.

  • Links statements replace existing role players of the specified player’s role (isa!) with the specified instance. Role tags can be omitted if there is only a single role the role player can play.

Update stages cannot bind new variables.

If there is no data to existing replace, the operation is equivalent to insert.

Execution

The update stage must be preceded by other stages. The body of the update stage is executed once for each input row. The output is then a stream equivalent to the input rows, as no variables are modified.

Validation

Only unambiguous operations on owns and relates with cardinalities limited by 1 are allowed.

The modified concepts are validated the same way as in insert stages.

Example

match
  $group isa group, has group-id "<group id>";
  $user isa user, has username "<username>";
  $group-membership isa group-membership, has rank "admin", links (member: $user);
update
  $group-membership has rank "member";
  $group-membership links (group: $group);