pg_typeof
The pg_typeof() function allows you to retrieve the data type of any given value. It returns a string literal corresponding to the expression type.
The syntax of the pg_typeof() function is:
Here, any represents any value you want to determine the data type.
This case shows a basic example with a numeric value:
It will return its data type, which is “integer”.
Here, we will use a string value as an input:
It will return its data type, which is “text”.
Another example is using an interval input:
It will return its data type in string literal.
Suppose you have a sample table and want to use pg_typeof() to retrieve their data types.
1) Create the table and insert some data into the table.
2) Now, use pg_typeof() to determine the data types of the event_time and description columns for each row.
3) The result will show that the data type of the event_time column is a timestamp, and the data type of the description column is text:
