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

CAST



Converts a value from one data type to another. :: is an alias for CAST.

See also: TRY_CAST

Syntax

CAST( <expr> AS <data_type> ) <expr>::<data_type>

Examples

SELECT CAST(1 AS VARCHAR), 1::VARCHAR; ┌───────────────────────────────┐ │ cast(1 as string) │ 1::string │ ├───────────────────┼───────────┤ │ 11 │ └───────────────────────────────┘

Cast String to Variant and Cast Variant to Map<String, Variant>

select '{"k1":"v1","k2":"v2"}'::Variant a, a::Map(String, String) b, b::Variant = a; ┌──────────────────────┬──────────────────────┬────────────────┐ │ a │ b │ b::VARIANT = a │ ├──────────────────────┼──────────────────────┼────────────────┤ │ {"k1":"v1","k2":"v2"}│ {'k1':'v1','k2':'v2'}│ 1 │ └──────────────────────┴──────────────────────┴────────────────┘

Was this page helpful?