IMPORTANT: No additional bug fixes or documentation updates
will be released for this version. For the latest information, see the
current release documentation.
Type Conversion Functions
editType Conversion Functions
editThis functionality is in technical preview and may be changed or removed in a future release. Elastic will work to fix any issues, but features in technical preview are not subject to the support SLA of official GA features.
Functions for converting an expression of one data type to another.
CAST
editSynopsis.
DescriptionCasts the result of the given expression to the target data type. If the cast is not possible (for example because of target type is too narrow or because the value itself cannot be converted), the query fails.
SELECT CAST('123' AS INT) AS int; int --------------- 123
SELECT CAST(123 AS VARCHAR) AS string; string --------------- 123
SELECT YEAR(CAST('2018-05-19T11:23:45Z' AS TIMESTAMP)) AS year; year --------------- 2018
CONVERT
editSynopsis.
DescriptionWorks exactly like CAST
with slightly different syntax.
Moreover, apart from the standard data types it supports the corresponding
ODBC data types.
SELECT CONVERT('123', SQL_INTEGER) AS int; int --------------- 123
SELECT CONVERT('123', INTEGER) AS int; int --------------- 123