Officially out now: The TypeDB 3.0 Roadmap >>

@range annotation

The @range annotation is used to specify a range of permitted values for attributes.

Syntax

Value annotation syntax
<type label> value <value type> @range(N..M);
<type label> value <value type> @range(N..);
<type label> value <value type> @range(..M);
Ownership annotation syntax
<type label> owns <attribute type label> @range(N..M);
<type label> owns <attribute type label> @range(N..);
<type label> owns <attribute type label> @range(..M);

The @range annotation can be defined for either an attribute type’s value type or an ownership.

The @range annotation accepts either a range argument or a single scalar argument. Arguments must match the value type of <attribute type label>. See Supported value types for the list of supported value types.

Partially unbounded ranges N.. and ..M represent ranges without an upper and lower bounds, respectively.

Usage

The @range annotation adds a constraint on values of attributes of a given attribute type to be within the specified range.

When defined for an attribute type’s value type, the annotation creates a constraint for any attribute of this attribute type.

define
  attribute latitude value double @range(-90.0..90.0);

When defined for an ownership, the annotation creates a constraint for any attribute of this attribute type owned by the owner type. In the following example, an instance of the creation-timestamp type can contain any value, but a post can have (has) only the creation-timestamp s with the suitable values.

define
  entity post owns creation-timestamp @range(1970-01-01T00:00:00..);
  attribute creation-timestamp, value datetime;

Subtyping for attribute types' values

The range constraint put on an attribute types' value type is inherited. This means that values of all subtypes of a constrained type are also constrained, and it cannot be changed.

A subtype can introduce an even stricter constraint to allow only a subrange of the inherited range for its values.

Subtyping for ownerships

The range constraint put on an ownership should be respected by all the sub attribute types owned by this owner. This way, any instance of any subtype of the creation-timestamp owned by any instance of any subtype of the post should comply to the defined range.

Ownerships of these subtypes can have their own range constraints, and they will be respected similarly down the inheritance line.

Limitations

See Supported value types for the list of supported value types.

References

Supported value types

The @range annotation is applicable only to value types with a defined ordering for their values.

Table 1. Supported value types

Value type

Supported?

Comment

boolean

integer

double

decimal

string

date

datetime

datetime-tz

duration