Return the dialect-neutral data type name of an expression.
TYPEOF(expr)
## Overview Returns the dialect-neutral name of the data type of the input expression. Use this function for diagnostics and schema exploration when you want consistent type names across engines. TYPEOF is the dialect-neutral variant of PG_TYPEOF. TYPEOF returns names such as `string`, `integer`, `boolean`; PG_TYPEOF returns the PG-compat equivalents (`text`, `integer`, `boolean`). ## Behavior - Always returns a non-NULL string. - For NULL inputs the type name is reported as `null`. - Deterministic for a given expression tree. - Side effect free. - The type is resolved at plan time from the expression's inferred type, not the runtime value. ## Compatibility - Dialect-neutral alternative to PG_TYPEOF.
| Name | Type | Description |
|---|---|---|
expr | Specifies the expression whose data type name is returned. |
-- Type of an integer
SELECT TYPEOF(42); -- 'integer'
-- Type of a string
SELECT TYPEOF('hello'); -- 'string'
-- Type of a boolean
SELECT TYPEOF(true); -- 'boolean'
-- Type of NULL (reported as 'null')
SELECT TYPEOF(NULL); -- 'null'
-- Inspect column types in a sample row
SELECT TYPEOF(price) AS price_type, TYPEOF(quantity) AS qty_type
FROM retail.catalog.products
LIMIT 1;