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
falseequivalent to0for empty string types,trueis equivalent to all other values. - The conversions from/to bool consider
falseequivalent to0for int types,trueis equivalent to all other values. - The conversions from/to bool consider
falseequivalent to0.0for float types,trueis equivalent to all other values.
- The conversions from/to bool consider
-
intcan 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.