Skip to main content

Casting

In the SurrealDB type system, values can be converted to other values efficiently. This is useful if input is specified in a query which must be of a certain type, or if a user may have provided a parameter with an incorrect type.

TypeDescription
<bool>Casts the subsequent value into a boolean
<int>Casts the subsequent value into a int
<float>Casts the subsequent value into a float
<string>Casts the subsequent value into a string
<number>Casts the subsequent value into a decimal
<decimal>Casts the subsequent value into a decimal
<datetime>Casts the subsequent value into a datetime
<duration>Casts the subsequent value into a duration

<bool>

The <bool> casting function converts a value into a boolean.

SELECT * FROM <bool> "true";

true
SELECT * FROM <bool> "false";

false

<int>

The <int> casting function converts a value into an integer.

SELECT * FROM <int> 53;

53

<float>

The <float> casting function converts a value into a floating point number.

SELECT * FROM <float> 13.572948467293847293841093845679289;

13.572948467293847
SELECT * FROM <float> "13.572948467293847293841093845679289";

13.572948467293847

<string>

The <string> casting function converts a value into a string.

SELECT * FROM <string> true;

"true"
SELECT * FROM <string> 1.3463;

"1.3463"
SELECT * FROM <string> false;

"false"

<number>

The <number> casting function converts a value into an infinite precision decimal number.

SELECT * FROM <number> 13.572948467293847293841093845679289;

"13.572948467293847293841093845679289"
SELECT * FROM <number> "13.572948467293847293841093845679289";

"13.572948467293847293841093845679289"
SELECT * FROM <number> 1.193847193847193847193487E11;

"119384719384.7193847193487"

<decimal>

The <decimal> casting function converts a value into an infinite precision decimal number.

SELECT * FROM <decimal> 13.572948467293847293841093845679289;

"13.572948467293847293841093845679289"
SELECT * FROM <decimal> "13.572948467293847293841093845679289";

"13.572948467293847293841093845679289"
SELECT * FROM <decimal> 1.193847193847193847193487E11;

"119384719384.7193847193487"

<datetime>

The <datetime> casting function converts a value into a datetime.

SELECT * FROM <datetime> "2022-06-07";

"2022-06-07T00:00:00Z"

<duration>

The <duration> casting function converts a value into a duration.

SELECT * FROM <duration> "1h30m";

"1h30m"