Value types

A value type classifies the concrete data a TypeQL query evaluates and stores. Unlike entity, relation, and attribute types, value types are built into the language rather than declared in a schema, and they cannot be subtyped or given capabilities.

Where value types are used

Value types appear in the following contexts.

Attribute value types

Every attribute type is defined with an associated value type using the value keyword, which fixes the value that its attributes carry:

define attribute start-date value date;

The same keyword retrieves attribute types by value type in a pattern, as in match $a value date;.

Literals

A literal written directly in a query is a constant of the value type determined by its syntax: 1 is an integer, 1.0 a double, true a boolean. Literals supply attribute values on insertion, operands in expressions and comparisons, arguments to function calls, and arguments to value constraints.

Value variables

A variable assigned with let holds a computed value rather than a stored data instance. Its value type is inferred from the expression that produces it, and is checked when the query is compiled:

match let $x = 1 + 1;

Function signatures

A function declares the type of each argument and each returned element. These may be value types as well as user-defined types:

fun mean-karma($u: user) -> double:

Comparisons

Value types determine which comparisons are legal. Values may only be compared within a comparable group, and boolean and duration values compare for equality only.

Value constraints

The @values, @range, and @regex annotations take literal arguments that must match the value type of the attribute type they constrain. Each annotation supports a specific set of value types.

Supported value types

TypeQL provides the following value types.

Name TypeQL Description

Boolean

boolean

A logical boolean (true / false).

Integer

integer

A 64-bit signed integer.

Double

double

A double precision IEEE 754 floating point number.

Decimal

decimal

A fixed point signed decimal number.

String

string

A UTF-8 character string type.

Date

date

An ISO 8601 compliant date type.

Datetime

datetime

An ISO 8601 compliant date and time type.

DatetimeTZ

datetime-tz

An ISO 8601 compliant date and time type with time zone information.

Duration

duration

An ISO 8601 compliant duration type.