Conversion Functions

Polars SQL supports explicit casts for scalar values. Do not rely on implicit conversion rules unless the behavior is documented on the specific operator or function page.

CAST

cast(value AS type) -> type()

Explicitly cast a value as a type.

Verified target types and aliases include BOOLEAN/BOOL, SMALLINT, INTEGER, BIGINT/LONG, DOUBLE, FLOAT/REAL, VARCHAR/STRING, DATE, and TIMESTAMP.

Numeric values can be cast to string types, strings can be cast to numeric types, and strings can be cast to DATE or TIMESTAMP. Casting NULL returns NULL of the requested type.

Note

When casting strings to SMALLINT or INTEGER, leading and trailing spaces are allowed.