Conversion Functions

This page lists all conversion functions available in Spark SQL.


bigint

bigint(expr) - Casts the value expr to the target data type bigint.

Since: 2.0.1


binary

binary(expr) - Casts the value expr to the target data type binary.

Since: 2.0.1


boolean

boolean(expr) - Casts the value expr to the target data type boolean.

Since: 2.0.1


cast

cast(expr AS type) - Casts the value expr to the target data type type. expr :: type alternative casting syntax is also supported.

Examples:

> SELECT cast('10' as int);
 10
> SELECT '10' :: int;
 10

Since: 1.0.0


date

date(expr) - Casts the value expr to the target data type date.

Since: 2.0.1


decimal

decimal(expr) - Casts the value expr to the target data type decimal.

Since: 2.0.1


double

double(expr) - Casts the value expr to the target data type double.

Since: 2.0.1


float

float(expr) - Casts the value expr to the target data type float.

Since: 2.0.1


int

int(expr) - Casts the value expr to the target data type int.

Since: 2.0.1


smallint

smallint(expr) - Casts the value expr to the target data type smallint.

Since: 2.0.1


string

string(expr) - Casts the value expr to the target data type string.

Since: 2.0.1


time

time(expr) - Casts the value expr to the target data type time.

Since: 2.0.1


timestamp

timestamp(expr) - Casts the value expr to the target data type timestamp.

Since: 2.0.1


tinyint

tinyint(expr) - Casts the value expr to the target data type tinyint.

Since: 2.0.1