Officially out now: The TypeDB 3.0 Roadmap >>

sub statement

The statement <LABEL> sub <SUPERTYPE LABEL> is used to identify the <LABEL> type as a subtype of <SUPERTYPE LABEL>.

Defining subtyping

The sub keyword can be used to define a type as a subtype of another type.

define user sub profile;

Undefining subtyping

The sub keyword can be used to undefine a type’s subtyping of a type.

undefine sub profile from user;

Matching

Matching supertypes

The sub keyword can be used to match all supertypes of a type. This will result in all the transitive supertypes, including supertypes of its supertype.

match user sub $t;
Example TypeDB Console output
   --------
    $t | type content
   --------
    $t | type page
   --------
    $t | type profile
   --------
    $t | type user
   --------

Matching declared supertypes

The sub! keyword can be used to match only a declared supertype of a type. This will result in only the types with defined sub statements, excluding the subtypes of these types.

match user sub! $t;
Example TypeDB Console output
   --------
    $t | type profile
   --------

Matching subtypes

The sub keyword can be used to match all subtypes of a <SUPERTYPE LABEL>. This will result in all the transitive subtypes, including subtypes of its subtypes.

match $t sub profile;
Example TypeDB Console output
   --------
    $t | type profile
   --------
    $t | type user
   --------
    $t | type organisation
   --------
    $t | type company
   --------
    $t | type charity
   --------
    $t | type educational-institute
   --------
    $t | type school
   --------
    $t | type college
   --------
    $t | type university
   --------

Matching declared subtypes

The sub! keyword can be used to match only declared subtypes of a type. This will result in only the types with defined sub statements, excluding the subtypes of these types.

match $t sub! profile;
Example TypeDB Console output
   --------
    $t | type user
   --------
    $t | type organisation
   --------