Search code examples
sqlpostgresqlsqldatatypes

how do I return the sql data types from my query in pgsql?


How do I return the data types of a query from a Postgres SQL database?

Is there a function I can put in my query to do this for a particular column, I am wondering this especially for calculated columns.


Solution

  • You're looking for a function pg_typeof(any).

    For your case it can be used as:

    SELECT pg_typeof(calculated_column_name) FROM (your_main_query_here);