Type Conversion¶
Converting an expression of a given type to another type is known as type-conversion. In nGQL, type conversion is divided into implicit conversion and explicit conversion.
Implicit Type Conversion¶
Implicit conversions are automatically performed when a value is copied to a compatible type.
-
Following types can implicitly converted to
bool
:- The conversions from/to bool consider
false
equivalent to0
for empty string types,true
is equivalent to all other values. - The conversions from/to bool consider
false
equivalent to0
for int types,true
is equivalent to all other values. - The conversions from/to bool consider
false
equivalent to0.0
for float types,true
is equivalent to all other values.
- The conversions from/to bool consider
-
int
can implicitly converted todouble
.
Explicit Type Conversion¶
In addition to implicit type conversion, explicit type conversion is also supported in case of semantics compliance. The syntax is similar to the C
language:
(type_name)expression
.
For example, the results of YIELD length((string)(123)), (int)"123" + 1
are 3, 124
respectively. The results of YIELD (int)(TRUE)
is 1
. And YIELD (int)("12ab3")
fails in conversion.