📣
TiDB Cloud Premium is now in public preview. Unlimited growth, instant elasticity, advanced security for enterprise workloads. Try it out →

Type Conversion Functions



This section provides reference information for type conversion functions in TiDB Cloud Lake. These functions enable strict casting of VARIANT values to other SQL data types.

Type Conversion

FunctionDescriptionExample
AS_BOOLEANConverts a VARIANT value to BOOLEANAS_BOOLEAN(PARSE_JSON('true'))true
AS_INTEGERConverts a VARIANT value to BIGINTAS_INTEGER(PARSE_JSON('42'))42
AS_FLOATConverts a VARIANT value to DOUBLEAS_FLOAT(PARSE_JSON('3.14'))3.14
AS_DECIMALConverts a VARIANT value to DECIMALAS_DECIMAL(PARSE_JSON('12.34'))12.34
AS_STRINGConverts a VARIANT value to STRINGAS_STRING(PARSE_JSON('"hello"'))'hello'
AS_BINARYConverts a VARIANT value to BINARYAS_BINARY(TO_BINARY('abcd')::VARIANT)61626364
AS_DATEConverts a VARIANT value to DATEAS_DATE(TO_DATE('2025-10-11')::VARIANT)2025-10-11
AS_ARRAYConverts a VARIANT value to ARRAYAS_ARRAY(PARSE_JSON('[1,2,3]'))[1,2,3]
AS_OBJECTConverts a VARIANT value to OBJECTAS_OBJECT(PARSE_JSON('{"a":1}')){"a":1}

Important Notes

  • These functions perform strict casting of VARIANT values
  • If the input data type is not VARIANT, the output is NULL
  • If the type of value in the VARIANT does not match the expected output type, the output is NULL
  • All AS_* functions ensure type safety by returning NULL for incompatible conversions

Was this page helpful?