Type conversion functions are used to convert the data type of a specified value or column in a query.

Fields in index attributes of Log Service can be configured as the long, double, text, or JSON type. Log Service also supports querying fields of various data types, including bigint, double, varchar, and timestamp. To query fields of a specific data type, you can use type conversion functions to convert the data type configured in index attributes into the data type used in the query.

Function format

Note We recommend that you use the try_cast() function if the logs contain dirty data. Otherwise, the entire query may fail due to the dirty data.
  • Convert a column (field) or a constant value into the specified type in a query. If the value fails to be converted, the entire query is terminated.
    cast([key|value] AS type)
  • Convert a column (field) or a constant value into the specified type in a query. If the value fails to be converted, NULL is returned for the value, and the query continues.
    try_cast([key|value] AS type)
Parameter Description
key The key of the log. If you set this parameter, all values of this parameter are converted into the specified type.
value The constant value. If you set this parameter, the specified value is converted into the specified type.

Example

  • To convert number 123 into a string in varchar format, run the following statement:
    cast(123 AS varchar)
  • To convert all values of the uid field into a string in varchar format, run the following statement:
    cast(uid AS varchar)