Types
SurrealQL allows you to describe data with specific data types. These data types are used to validate data and to generate the appropriate database schema.
Data types
| Type | Description |
|---|---|
any
| Use this when you explicitly don't want to specify the field's data type. The field will allow any data type supported by SurrealDB. |
array
| An array of items. The array type also allows you to define which types can be stored in the array and the required length. |
bool
|
A value that can be either true or false.
|
bytes
| Stores a value in a byte array. |
datetime
| An RFC 3339 compliant data type that stores a date with time and time zone. |
decimal
| Data type for storing decimal floating point numbers. |
duration
| Store a value representing a length of time. Can be added or subtracted from datetimes or other durations. |
float
| Data type for storing floating point numbers. Larger or extremely precise values should be stored as a decimal. |
geometry
| RFC 7946 compliant data type for storing geometry in the GeoJson format. |
int
|
Store a value in a 64 bit signed integer. Values can range between -9223372036854775808 and 9223372036854775807 (inclusive). Larger values should be stored as a float or a decimal.
|
number
| Store numbers without specifying the type. SurrealDB will detect the type of number and store it using the minimal number of bytes. |
object
| Store formatted objects containing values of any supported type including nested objects or arrays. |
range
| A range of possible values. Lower and upper bounds can be set, in the absence of which the range becomes open-ended. A range of integers can be used in a FOR loop. |
regex
| A regular expression that can be used for matching strings. |
record
| A record ID. Table names can be added inside angle brackets to restrict to certain table names. |
set
| A set of items. The set type also allows you to define which types can be stored in the set and the required length. Items are automatically deduplicated and orderd. |
string
| A value composed of text or text-like characters such as emojis. |
Examples
Examples of the geometry type:
Examples of the bytes type:
Type expressions
Type expressions are not standalone types, but expressions to indicate which types are permitted.
| Type | Description |
|---|---|
| literal | A value that may have multiple representations or formats, similar to an enum or a union type. Can be composed of strings, numbers, objects, arrays, or durations. |
option
|
Makes types optional and guarantees the field to be either empty (NONE) or some other type. Syntactic sugar for type_name | NONE.
|
Examples
Example of an option in a schema:
Example of a literal type:
As an option is syntactic sugar for type | NONE, an option is also simply another type of literal. This field definition is identical to the option example above.