Reputation: 13852
How can I introspect the types returned from a SQL query. I can introspect the table to get the columns and types, but during run time, there may be fields that are not in the db (for example, the concat
method). Here is an example:
SELECT id, email, number_of_logins, concat(first_name, last_name) as full_name from users
Is there a way to find the types?
Upvotes: 0
Views: 426
Reputation: 246493
With recent versions of psql
, you can simply use \gdesc
rather than ;
to end your query:
SELECT 42 AS x \gdesc
Column | Type
--------+---------
x | integer
(1 row)
Upvotes: 1
Reputation: 789
You can check using pg_catalog.format_type(concat(first_name, last_name))
also try pg_typeof(col)
SELECT id, email, number_of_logins, pg_catalog.format_type(concat(first_name, last_name)) as full_name from users
Upvotes: 3