SurrealDB Docs Logo

Enter a search query

Data 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.

TypeDescription
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 max length.

  • array
  • array<string>
  • array<string, 10>
bool

Describes whether something is truthy or not.

bytes

Stores a value in a byte array.

  • <bytes>value
  • bytes
datetime

An ISO 8601 compliant data type that stores a date with time and time zone.

decimal

Uses BigDecimal for storing any real number with arbitrary precision.

duration

Store a value representing a length of time. Can be added or subtracted from datetimes or other durations.

float

Store a value in a 64 bit float.

geometry

RFC 7946 compliant data type for storing geometry in the GeoJson format.

  • geometry<feature>
  • geometry<point>
  • geometry<LineString>
  • geometry<polygon>
  • geometry<multipoint>
  • geometry<multiline>
  • geometry<multipolygon>
  • geometry<collection>
int

Store a value in a 64 bit integer.

number

Store numbers without specifying the type. SurrealDB will detect the type of number and store it using the minimal number of bytes. For numbers passed in as a string, this field will store the number in a BigDecimal.

object

Store formatted objects containing values of any supported type with no limit to object depth or nesting.

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.

  • ”a” | “b”
  • [number, “abc”]
  • 123 | 456 | string | 1y1m1d
option

Makes types optional and guarantees the field to be either empty (NONE), or a number.

  • option<number>
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.

  • 0..10
  • 0..=10
  • ..10
  • ‘a’..‘z’
record

Store a reference to another record. The value must be a Record ID. Add the record name inside angle brackets to restrict the reference to only certain record names.

  • record
  • record<user>
  • record<user | administrator>
set

A set of items. The set type also allows you to define which types can be stored in the set and the max length. Items are automatically deduplicated.

  • set
  • set<string>
  • set<string, 10>
string

Describes a text-like value.

Examples

geometry

-- Define a field with a single type DEFINE FIELD location ON TABLE restaurant TYPE geometry<point>; -- Define a field with any geometric type DEFINE FIELD area ON TABLE restaurant TYPE geometry<feature>; -- Define a field with specific geometric types DEFINE FIELD area ON TABLE restaurant TYPE geometry<polygon|multipolygon|collection>;

bytes

-- Define a field with a single type DEFINE FIELD image ON TABLE product TYPE bytes; -- Create a record with a bytes field and set the value CREATE foo SET value = <bytes>"bar";

On this page

© SurrealDB GitHub Discord Community Cloud Features Releases Install