Update stage
An update stage updates data in the database. Updatable data includes ownerships of attributes and role players of relations.
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 existing data to 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. In case multiple rows will update the same data, only the last update will persist. 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
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 group-id sub id;
attribute rank, value string @values("admin", "member");
attribute tag value string;
relation group-membership, relates group, relates member, owns rank;
entity group, owns name, owns group-id, owns tag, plays group-membership:group;
user, plays group-membership:member;
#!test[write]
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);