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, andTIMESTAMP.Numeric values can be cast to string types, strings can be cast to numeric types, and strings can be cast to
DATEorTIMESTAMP. CastingNULLreturnsNULLof the requested type.
Note
When casting strings to SMALLINT or INTEGER, leading and
trailing spaces are allowed.