TYPEOF
Purpose
This function returns the SQL data type of its argument.
Syntax
typeof::=
Usage Notes
- Returns a normalized version of the type. For example, if a column is defined using the data type alias
INT
,TYPEOF
returnsDECIMAL(18,0)
. - The type of any SQL expression is constant and the same for each row. Therefore,
TYPEOF
(expr) returns the same result for all rows, independent of the actual values of expression. - The return type of function
TYPEOF
isVARCHAR(40) UTF8
.
Example
CREATE SCHEMA TYPEOF_EXAMPLE;
CREATE TABLE TYPE_TABLE (int_col INT, char_col CHAR(5));
INSERT INTO TYPE_TABLE VALUES (NULL, NULL);
SELECT TYPEOF(int_col) AS type FROM TYPE_TABLE;
SELECT TYPEOF(char_col) AS type FROM TYPE_TABLE;
SELECT TYPEOF(TYPEOF(int_col)) FROM TYPE_TABLE;
select TYPEOF(1 * 0.1), TYPEOF(0.1 * 1);