Casting
Casting refers to the operation of converting a value that is of one particular data type, to another data type.
This is done in Kùzu using the CAST
function.
There are two ways to utilize the CAST
function. The syntax for either approach is below:
CAST(source, "type:)
: In this approach, you pass in the source value as an argument to theCAST
function, and the target data type as a string argument.CAST(source AS type)
: In this approach, you use theAS
keyword to cast the provided value to the target data type.
A floating-point number can be cast to an integer:
Returns:
Not all inputs can be cast to every data type. For example, INT[]
can not be cast to INT
. Even
if a cast between the input’s data type to the target type is well defined, the cast can still fail
if the input’s value is not suitable to cast. For example, casting the STRING
data type to
INT
is well defined — you cannot cast "abc"
to INT
, but you can cast "12"
to INT
.
Returns:
A string array can be cast to an integer array as follows:
Returns: