Modifiers are natural language functions that convert one value to another. Typically, they are categorized by the data type they operate on. However, some modifiers are not specific to a particular data type or category, as is the case with the modifiers in this section.
The following table summarizes these other modifiers for quick reference:
|Cast||Converts a value from one type to another.|
This modifier converts a value from one type to another. It is particularly useful when comparing values of different types, or when passing a value of one type to a function that requires a different type.
The cast modifier follows the same logic as any other conversion in CQL, meaning that explicitly casting a value to a number works just like an implicit conversion when passing a value to a function that requires a number. See conversions for more details.
This modifier has the following syntax:
/*<value>*/ as /*<type>*/
The /*<mode>*/ is a literal word that specifies the target type and cannot be specified dynamically using expressions.
The following table lists the supported types:
|boolean||Converts the value to a boolean.|
|string||Converts the value to a string.|
|number||Converts the value to a number.|
|integer||Converts the value to an integer.|
|decimal||Converts the value to a decimal.|
|float||Converts the value to a float.|
|collection||Converts the value to a collection.|
|time||Converts the value to a local time.|
|date||Converts the value to a local date.|
|datetime||Converts the value to a zoned date-time.|
Note that attempting to cast a type not listed above results in an error.
These are the supported parameters:
The value you want to convert.
Here is a basic example of how to convert a string to a date:
"2019-01-01" as date
You can also perform sequential conversions by chaining multiple casts together:
"2019-01-01" as datetime as date
In this last example, the string is first converted to a zone date-time, then to a local date. Note that a direct conversion to a date may produce a different result, since no time zone conversion is performed.