PostgreSQL 18 reference · Conditional and Type Expressions
PostgreSQL PG_TYPEOF() Function
Return the data type of a value as a name, such as integer, numeric or text. Useful for debugging casts.
PostgreSQL 18
Syntax
pg_typeof(any)
Parameters
| Parameter | Description |
|---|---|
any |
Any value or expression. |
Return value
The type name (regtype).
Examples
SELECT pg_typeof(42) AS a, pg_typeof(4.2) AS b, pg_typeof('x'::text) AS c, pg_typeof(now()) AS d;
Output
a | b | c | d ---------+---------+------+-------------------------- integer | numeric | text | timestamp with time zone (1 row)
Run this on your computer — see “Get Started” for setup.
SELECT pg_typeof(price) AS price_type, pg_typeof(order_date) AS date_type
FROM products, orders
LIMIT 1;
Output
price_type | date_type ------------+----------- numeric | date (1 row)
Run this on your computer — see “Get Started” for setup.
In other languages
TYPEOF()· SQLite
Related
CAST and ::· Convert a value to another type with CAST(x AS type) or the PostgreSQL shorthand x::type. Invalid input raises an error.- SQL Aggregate Functions · tutorial