How to check type of value in postgres
⚡TLDR
To find out the data type of a value in PostgreSQL, use the pg_typeof()
function:
Returns: text
Output: Data type of entity hiding in column_name
e.g., integer
, boolean
.
Conditional operations based on type
With the help of CASE statement, decide which action based on value type:
Diving deep: Explore PostgreSQL's system catalogs
Looking to go on an Indiana Jones adventure raiding PostgreSQL's warehouse of data types? Our faithful guides are pg_type
and pg_catalog.pg_namespace
.
Handling tricky cases and pitfalls
pg_typeof
is a great level one wizard spell, but sometimes you need a level two (or even higher) spell for complex type invocations.
Exceptions: The bodyguard of type casting
Like the bodyguard who takes the bullet, exceptions shield your cast operation if it fails:
Linked
Linked
Was this article helpful?