TYPEOF
Function
Returns the data type of an expression. Useful for querying type information about expressions or columns, especially in dynamic SQL and type-checking scenarios.
Parameters
expr: An expression of any type
Return Value
- string type
- Returns the name of the expression's data type
- For primitive types, returns the type name (e.g.,
'int','string','boolean') - For complex types, returns the full type definition (e.g.,
array<...>,map<...>,struct<...>)
Examples
Notes
typeofreturns a type name string, not a type object- For decimal types, the full precision information is returned, e.g.,
'decimal(10,2)' - For complex types (array, map, struct), the full nested type definition is returned
- Field names in
structtypes default tocol1,col2,col3, etc. - The function resolves types at compile time and does not change at runtime
- Common use cases:
- Debugging and diagnostics
- Generating type-related metadata
- Note:
TYPEOFreturns only type information and does not include NULL constraint information - The function has minimal performance impact because type information is determined at compile time
