SurrealDB uses two types called None
and Null
to represent two different ways in which data may not exist. While these may appear similar, they have different meanings and are used in different contexts.
None
is used to denote that “something does not exist”, for example, a field which is not present on a record. Because of this, values of None
can not be stored within records, meaning uses of None
are typically limited to SurrealQL statements where it is used to denote a value or response that does not exist.
Setting a record field to None
is analogous to using UNSET
to remove the field entirely.
UPDATE person SET children = NONE;
While it may appear that None
is being written to the children
field, what is actually happening is that the children
field is being removed from the record.
SELECT * FROM person; -- Returns { id: person:2cz8rj0dc4tktxlkjquc }
Null
values are used to denote that “something exists, but has no value”. This is useful when a field is present on a record, but the value of that field is unknown or not applicable. Unlike None
, Null
is written into records and can be stored as a value.
Setting a record field to Null
will create the field on the record, but denotes that the field is considered empty.
UPDATE person SET children = null;
In this example, the children
field is present on the record, but the value of that field is null
.
SELECT * FROM person; -- Returns { id: person:2cz8rj0dc4tktxlkjquc, children: null }
How you use None
or Null
is largely dependent on the context in which you are working.
If you are writing SurrealQL and need to denote something that does not exist, such as the absence of a field, use None
.
If you are working with data and need to represent a value which is empty, use Null
.