Strings
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";
String prefixes
In SurrealQL, strings can be enthusiastically converted into Record IDs, Datetimes or to UUIDs. String prefixes are a solution to this problem, in that you as the developer get to specify what the "string" contains.
Overview
Here are a couple of examples of how string prefixes work:
RETURN s"5:20";
RETURN r"person:tobie";
s
-> string
The s
prefix tells the parser that the contents of this string is just a string, and likely the most common usecase for string prefixes.
-- Interpeted as a record ID, because of the structure with the semicolon:
RETURN "5:20";
-- Forcefully parsed as just a string
RETURN s"5:20";
r
-> record
The r
prefix tells the parser that the contents of this string is a record ID.
RETURN r"person:john";
d
-> datetime
The d
prefix tells the parser that the contents of this string is a DateTime.
RETURN d"2023-11-28T11:41:20.262Z";
u
-> UUID
The u
prefix tells the parser that the contents of this string is a UUID.
RETURN u"8c54161f-d4fe-4a74-9409-ed1e137040c1";