Back to top
  Back to overview

Type functions

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::bool() Converts a value into a boolean
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::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::point() Converts a value into a geometry point
type::regex() Converts a value into a regular expression
type::string() Converts a value into a string
type::table() Converts a value into a table
type::thing() Converts a value into a record pointer

type::bool

The type::bool function converts a value into a bool, if the value is truthy.

type::bool(value) -> boolean

The following example shows this function, and its output, when used in a select statement:

SELECT * FROM type::bool(12345);
true

This is the equivalent of using <bool> to cast a value to a boolean.

type::datetime

The type::datetime function converts a value into a datetime.

type::datetime(value) -> datetime

The following example shows this function, and its output, when used in a select statement:

SELECT * FROM type::datetime("2022-04-27T18:12:27+00:00");
"2022-04-27T18:12:27Z"

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.

type::decimal(value) -> decimal

The following example shows this function, and its output, when used in a select statement:

SELECT * FROM type::decimal("12345");
"12345"

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.

type::duration(value) -> duration

The following example shows this function, and its output, when used in a select statement:

SELECT * FROM type::duration("4h");
"4h"

This is the equivalent of using <duration> to cast a value to a duration.

type::float

The type::float function converts a value into a float.

type::float(value) -> float

The following example shows this function, and its output, when used in a select statement:

SELECT * FROM type::float("12345");
12345.0

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.

type::int(value) -> int

The following example shows this function, and its output, when used in a select statement:

SELECT * FROM type::int("12345");
12345

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.

type::number(value) -> number

The following example shows this function, and its output, when used in a select statement:

SELECT * FROM type::number("12345");
"12345"

This is the equivalent of using <number> to cast a value to a number.

type::point

The type::point function converts a value into a geometry point.

type::point(value) -> point

This function also accepts two arguments (longitude and latitude values).

type::point(number, number) -> point

The following examples show this function, and its output, when used in a select statement:

SELECT * FROM type::point(51.509865, -0.118092);
{
	"type": "Point",
	"coordinates": [
		-0.10231019499999999,
		51.49576478
	]
}
SELECT * FROM type::point([51.509865, -0.118092]);
{
	"type": "Point",
	"coordinates": [
		-0.10231019499999999,
		51.49576478
	]
}

type::regex

The type::regex function converts a value into a regex.

type::regex(value) -> regex

The following example shows this function, and its output, when used in a select statement:

SELECT * FROM type::regex("/[A-Z]{3}/");
FIXME

type::string

The type::string function converts a value into a string.

type::string(value) -> string

The following example shows this function, and its output, when used in a select statement:

SELECT * FROM type::string(12345);
"12345"

This is the equivalent of using <string> to cast a value to a string.

type::table

The type::table function converts a value into a table definition.

type::table(value) -> table

The following example shows this function, and its output, when used in a select statement:

LET $table = "person";
SELECT * FROM type::table($table);

type::thing

The type::thing function converts a value into a record pointer definition.

type::thing(value, value) -> thing

The following example shows this function, and its output, when used in a select statement:

LET $tb = "person";
LET $id = "tobie";
SELECT * FROM type::thing($tb, $id);