Type Functions
Note
These functions can be used for generating and coercing data to specific data types. These functions are useful when accepting input values in client libraries, and ensuring that they are the desired type within SQL statements.
| Function | Description |
|---|---|
type::array() | Converts a value into an array |
type::bool() | Converts a value into a boolean |
type::bytes() | Converts a value into bytes |
type::datetime() | Converts a value into a datetime |
type::decimal() | Converts a value into a decimal |
type::duration() | Converts a value into a duration |
type::field() | Projects a single field within a SELECT statement |
type::fields() | Projects a multiple fields within a SELECT statement |
type::file() | Converts two strings into a file pointer |
type::float() | Converts a value into a floating point number |
type::int() | Converts a value into an integer |
type::number() | Converts a value into a number |
type::of() | Returns the type of a value |
type::point() | Converts a value into a geometry point |
type::record() | Converts a value into a record pointer |
type::string() | Converts a value into a string |
type::table() | Converts a value into a table |
type::range() | Converts a value into a range |
type::uuid() | Converts a value into a UUID |
type::is_array() | Checks if given value is of type array |
type::is_bool() | Checks if given value is of type bool |
type::is_bytes() | Checks if given value is of type bytes |
type::is_collection() | Checks if given value is of type collection |
type::is_datetime() | Checks if given value is of type datetime |
type::is_decimal() | Checks if given value is of type decimal |
type::is_duration() | Checks if given value is of type duration |
type::is_float() | Checks if given value is of type float |
type::is_geometry() | Checks if given value is of type geometry |
type::is_int() | Checks if given value is of type int |
type::is_line() | Checks if given value is of type line |
type::is_none() | Checks if given value is of type none |
type::is_null() | Checks if given value is of type null |
type::is_multiline() | Checks if given value is of type multiline |
type::is_multipoint() | Checks if given value is of type multipoint |
type::is_multipolygon() | Checks if given value is of type multipolygon |
type::is_number() | Checks if given value is of type number |
type::is_object() | Checks if given value is of type object |
type::is_point() | Checks if given value is of type point |
type::is_polygon() | Checks if given value is of type polygon |
type::is_range() | Checks if given value is of type range |
type::is_record() | Checks if given value is of type record |
type::is_string() | Checks if given value is of type string |
type::is_uuid() | Checks if given value is of type uuid |
type::array
The type::array function converts a value into an array.
The following example shows this function, and its output, when used in a RETURN statement:
This is the equivalent of using <array> to cast a value to an array.
type::bool
The type::bool function converts a value into a boolean.
The following example shows this function, and its output, when used in a RETURN statement:
This is the equivalent of using <bool> to cast a value to a boolean.
type::bytes
The type::bytes function converts a value into bytes.
The following example shows this function, and its output, when used in a RETURN statement:
This is the equivalent of using <bytes> to cast a value to bytes.
type::datetime
The type::datetime function converts a value into a datetime.
The following example shows this function, and its output, when used in a RETURN statement:
This is the equivalent of using <datetime> to cast a value to a datetime.
type::decimal
The type::decimal function converts a value into a decimal.
The following example shows this function, and its output, when used in a RETURN statement:
This is the equivalent of using <decimal> to cast a value to a decimal.
type::duration
The type::duration function converts a value into a duration.
The following example shows this function, and its output, when used in a RETURN statement:
This is the equivalent of using <duration> to cast a value to a duration.
type::field
The type::field function projects a single field within a SELECT statement.
The following example shows this function, and its output:
This function can be used after the OMIT clause of a SELECT statement.
type::fields
The type::fields function projects one or more fields within a SELECT statement.
The following example shows this function, and its output:
This function can be used after the OMIT clause of a SELECT statement.
type::file
The type::file function converts two strings representing a bucket name and a key into a file pointer.
An example of a file pointer created using this function:
The following query shows the equivalent file pointer when created using the f prefix:
Once a bucket has been defined, operations using one of the file functions can be performed on the file pointer.
type::float
The type::float function converts a value into a float.
The following example shows this function, and its output, when used in a RETURN statement:
This is the equivalent of using <float> to cast a value to a float.
type::int
The type::int function converts a value into an integer.
The following example shows this function, and its output, when used in a RETURN statement:
This is the equivalent of using <int> to cast a value to a int.
type::number
The type::number function converts a value into a number.
The following example shows this function, and its output, when used in a RETURN statement:
This is the equivalent of using <number> to cast a value to a number.
type:of
The type::of function returns a string denoting the type of a value.
type::point
The type::point function converts a value into a geometry point.
The following example shows this function, and its output, when used in a RETURN statement:
type::range
The type::range function converts a value into a range. It accepts a single argument, either a range or an array with two values. If the argument is an array, it will be converted into a range, similar to casting.
The following example shows this function, and its output, when used in a RETURN statement:
type::record
Note
The type::record function converts a value into a record pointer definition.
The following example shows this function, and its output, when used in a RETURN statement:
An example of this function being used to turn an array of objects into records to be created or upserted:
An example of the same except in which the num field is to be used as the record's ID. In this case, it can be mapped with the array::map() function to rename num as id so that the following CONTENT clause does not create both a num and an id with the same value.
If the second argument passed into type::record is a record ID, the latter part of the ID (the record identifier) will be extracted and used.
The output of the above function call will thus be person:mat, not person:person:mat.
type::string
The type::string function converts any value except NONE, NULL, and bytes into a string.
The following example shows this function, and its output, when used in a RETURN statement:
This is the equivalent of using <string> to cast a value to a string.
type::string_lossy
The type::string_lossy function converts any value except NONE, NULL, and bytes into a string. In the case of bytes, it will not return an error if the bytes are not valid UTF-8. Instead, invalid bytes will be replaced with the character � (U+FFFD REPLACEMENT CHARACTER, used in Unicode to represent a decoding error).
The following example shows this function, and its output, when used in a RETURN statement:
This is similar to using <string> to cast a value to a string, except that an input of bytes will not fail.
type::table
The type::table function converts a value into a table name.
The following example shows this function, and its output, when used in a RETURN statement:
As of version 2.0, SurrealDB no longer eagerly parses strings into record IDs. As such, the output of the last item ("dog:two") in the following example will differ. In version 1.x, it will be eagerly parsed into a record ID after which the dog table name will be returned, while in version 2.x it will be treated as a string and converted into the table name dog:two.
type::uuid
The type::uuid function converts a value into a UUID.
The following example shows this function, and its output, when used in a RETURN statement:
type::is_array
Note
The type::is_array function checks if the passed value is of type array.
The following example shows this function, and its output, when used in a RETURN statement:
type::is_bool
Note
The type::is_bool function checks if the passed value is of type bool.
The following example shows this function, and its output, when used in a RETURN statement:
type::is_bytes
Note
The type::is_bytes function checks if the passed value is of type bytes.
The following example shows this function, and its output, when used in a RETURN statement:
type::is_collection
Note
The type::is_collection function checks if the passed value is of type collection.
The following example shows this function, and its output, when used in a RETURN statement:
type::is_datetime
Note
The type::is_datetime function checks if the passed value is of type datetime.
The following example shows this function, and its output, when used in a RETURN statement:
type::is_decimal
Note
The type::is_decimal function checks if the passed value is of type decimal.
The following example shows this function, and its output, when used in a RETURN statement:
type::is_duration
Note
The type::is_duration function checks if the passed value is of type duration.
The following example shows this function, and its output, when used in a RETURN statement:
type::is_float
Note
The type::is_float function checks if the passed value is of type float.
The following example shows this function, and its output, when used in a RETURN statement:
type::is_geometry
Note
The type::is_geometry function checks if the passed value is of type geometry.
The following example shows this function, and its output, when used in a RETURN statement:
type::is_int
Note
The type::is_int function checks if the passed value is of type int.
The following example shows this function, and its output, when used in a RETURN statement:
type::is_line
Note
The type::is_line function checks if the passed value is of type line.
The following example shows this function, and its output, when used in a RETURN statement:
type::is_none
Note
The type::is_none function checks if the passed value is of type none.
The following example shows this function, and its output, when used in a RETURN statement:
type::is_null
Note
The type::is_null function checks if the passed value is of type null.
The following example shows this function, and its output, when used in a RETURN statement:
type::is_multiline
Note
The type::is_multiline function checks if the passed value is of type multiline.
The following example shows this function, and its output, when used in a RETURN statement:
type::is_multipoint
Note
The type::is_multipoint function checks if the passed value is of type multipoint.
The following example shows this function, and its output, when used in a RETURN statement:
type::is_multipolygon
Note
The type::is_multipolygon function checks if the passed value is of type multipolygon.
The following example shows this function, and its output, when used in a RETURN statement:
type::is_number
Note
The type::is_number function checks if the passed value is of type number.
The following example shows this function, and its output, when used in a RETURN statement:
type::is_object
Note
The type::is_object function checks if the passed value is of type object.
The following example shows this function, and its output, when used in a RETURN statement:
type::is_point
Note
The type::is_point function checks if the passed value is of type point.
The following example shows this function, and its output, when used in a RETURN statement:
type::is_polygon
Note
The type::is_polygon function checks if the passed value is of type polygon.
The following example shows this function, and its output, when used in a RETURN statement:
type::is_range
Note
The type::is_range function checks if the passed value is of type range.
type::is_record
Note
The type::is_record function checks if the passed value is of type record.
The following example shows this function, and its output, when used in a RETURN statement:
Validate a table
type::is_string
Note
The type::is_string function checks if the passed value is of type string.
The following example shows this function, and its output, when used in a RETURN statement:
type::is_uuid
Note
The type::is_uuid function checks if the passed value is of type uuid.
The following example shows this function, and its output, when used in a RETURN statement:
Method chaining
Method chaining allows functions to be called using the . dot operator on a value of a certain type instead of the full path of the function followed by the value.