Back to top
Documentation SurrealQL Data model Basic types

Simple types

SurrealDB has a large number of simple built-in types. With an advanced type system, SurrealDB enables advanced storage, simplified comparison, complex data structures, and mathematical operations directly within the database.

Null values

Values can be specifically set to NULL in SurrealDB to denote a field which is set, but which does not have a value.

CREATE person SET children = null;

Booleans

Boolean values can be used to mark whether a field is true or false.

CREATE person SET newsletter = false, interested = true;

Boolean values can be written in anycase.

CREATE person SET newsletter = FALSE, interested = True;

Strings

Strings can be used to store text values. All text fields can include unicode values, emojis, and tabular and multine breaks.

CREATE person SET text = 'Lorem ipsum dolor sit amet';

Strings can be created using single quotation marks, or double quotation marks.

CREATE person SET text = "Lorem ipsum dolor sit amet";

Any string in SurrealDB can include unicode text.

CREATE person SET text = "I ❤️ SurrealDB";

Strings can also include line breaks.

CREATE person SET text = "This
is
over
multiple
lines";

Numbers

In SurrealDB numbers can be one of three types. Simple integers, floating point numbers, or complex decimal numbers with infinite precision.

If a number value is specified without any decimal point value and is within the range -9223372036854775808 to 9223372036854775807 then the value will be treated as an integer.

CREATE event SET year = 2022;

If a number value is specified with a decimal point, or is outside of the maximum range specified above, then the number will automatically be treated as an infinite length decimal value. This ensures that there is no loss of precision when performing mathematical calculations within SurrealDB.

CREATE event SET temperature = 41.5;

To use a specific type when specifying numeric values, you can cast the value to the desired type.

CREATE event SET
	year = <int> 2022,
	temperature = <float> 41.5,
	horizon = <decimal> 13.5719384719384719385639856394139476937756394756
;

The benefits of floating point numeric values is speed and storage size, but there is a limit to the numeric precision.

SELECT * FROM <float> 13.5719384719384719385639856394139476937756394756;
13.571938471938473

In addition, when using floating point number specifically, mathematical operations can result in a loss of precision (as is normal with other databases).

SELECT * FROM <float> 0.3 + <float> 0.3 + <float> 0.3 + <float> 0.1;
1.0000000000000002

However, as numbers are treated as decimal values by default, then no precision is lost when performing mathematical calculations inside the database.

SELECT * FROM 0.3 + 0.3 + 0.3 + 0.1;
1.0

UUIDs

SurrealDB will automatically detect and parse valid UUIDs within strings, and store them efficiently within the database. This ensures that the amount of storage used to store a UUID on disk and in memory, is as little as possible.

CREATE person SET identifier = "fb2cd733-eec4-4354-b070-3aba18c2a67a";

Objects

SurrealDB records can store objects, with no limit to the depth of any nested objects or values within. This means that objects and arrays can be stored within each other in order to model complex data scenarios. Objects can store any value stored within them, and can store different value types within the same object.

CREATE person SET metadata = {
	interest_level: 83.67,
	information: {
		age: 23,
		gender: 'm',
	},
	marketing: true,
	activities: [
		"clicked link",
		"contac form",
		"read email",
		"viewed website",
		"viewed website",
		"viewed website",
		"read email",
	]
};

Arrays

SurrealDB records can store arrays of values, with no limit to the depth of the arrays. This means that objects and arrays can be stored within each other in order to model complex data scenarios. Arrays can store any value stored within them, and can store different value types within the same array.

CREATE person SET results = [
	{ score: 76, date: "2017-06-18T08:00:00Z", name: "Algorithmics" },
	{ score: 83, date: "2018-03-21T08:00:00Z", name: "Concurrent Programming" },
	{ score: 69, date: "2018-09-17T08:00:00Z", name: "Advanced Computer Science 101" },
	{ score: 73, date: "2019-04-20T08:00:00Z", name: "Distributed Databases" },
];