SQL Function CAST

Syntax

CAST(value AS datatype[precision,scale])

Description

The CAST() function in Datameer's SQL worksheet converts a value into a specified data type.

Possible values type casts:
Source data typeto CAST as data type
any NumberINTEGER, DECIMAL, FLOAT
String of NumberINTEGER, DECIMAL, FLOAT
String of true/falseBOOLEAN
String of TimestampTIMESTAMP
any TypeVARCHAR
Cast data type conversions in Datameer
AS TYPE[(precision,scale)]resulting SheetColumnType
INTEGERInteger
FLOATFloat
DECIMAL(<20,0)Integer
DECIMAL(>=20,0)BigInteger
DECIMAL(<16,>=1)Float
DECIMAL(>=16,>=1)BigDecimal
DECIMALBigInteger
VARCHARString
BOOLEANBoolean
TIMESTAMPDate

Example


SQL commandReturnsColumn type
SELECT CAST(100.05 AS INTEGER)100String
SELECT CAST(100.05 AS FLOAT)100.05Float
SELECT CAST(100.05 AS DECIMAL(10,0))100Integer
SELECT CAST(100.05 AS DECIMAL(25,0))100.05BigInteger
SELECT CAST(100.05 AS DECIMAL(15,2))100.05Float
SELECT CAST(100.05 AS DECIMAL(18,2))100.05BigDecimal
SELECT CAST(100.05 AS DECIMAL)100BigInteger
SELECT CAST(100.05 AS VARCHAR)100.05String
SELECT CAST(true AS BOOLEAN)TrueBoolean
SELECT CAST('2019-02-14' AS TIMESTAMP)

Feb 14, 2019 12:00:00 AM

Date