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

Create a free account to save this page, take notes and track your progress. Sign in

Syntax

pg_typeof(any)

Parameters

ParameterDescription
any Any value or expression.

Return value

The type name (regtype).

Examples

Types of literals
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.

Columns in the sample database
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

Was this page helpful?