Officially out now: The TypeDB 3.0 Roadmap >>

has

The has keyword is used in TypeQL patterns to specify an owner for an attribute.

Syntax

The syntax of a has statement includes:

  • Subject — a concept variable representing a data instance

  • Predicate — the has keyword

  • Object — an attribute represented by an optional attribute type with a concept variable or literal value

Syntax
<data-instance> has <attribute>;

Behavior

TypeQL statements with the has keyword can be used in data queries to set a constraint of owning a particular attribute.

Usage in a match pattern

For this example, use a database with the IAM schema and sample data loaded.

To match a particular person by the value of the full-name it owns and return an email it owns:

has statement example
match
$p isa person, has full-name "Kevin Morrison", has email $e;
fetch $e;
See example output
Output example
{ "e": { "value": "kevin.morrison@typedb.com", "type": { "label": "email", "root": "attribute", "value_type": "string" } } }

Usage in an insert pattern

For this example, use a database with the IAM schema and sample data loaded.

Let’s insert a new email for an existing person:

Insert has example
match
$p isa person, has full-name "Kevin Morrison";
insert
$p has email "m.kevin@gmail.com";

By inserting ownership of an attribute that doesn’t exist in the database yet, we implicitly create such an attribute.

Usage in a delete pattern

For this example, use a database with the IAM schema and sample data loaded.

Let’s delete an ownership of the new email from the same person:

Delete has example
match
$p isa person, has full-name "Kevin Morrison", has email $e;
$e == "m.kevin@gmail.com";
delete
$p has $e;

The above example deletes only ownership, but the email attribute itself is still in the database. To delete the attribute, use the isa statement in a delete clause, for example, see the isa page.

Learn more

Learn about types in TypeQL.

Learn about data instances in TypeQL.