postgresqlpsql

Show query result column types (PostgreSQL)


Is there a way to easily get the column types of a query result? I read the psql documentation, but I don't think it supports that. Ideally, I'd be able to get something like:

 columna : text | columnb : integer
----------------+-------------------
 oh hai         |                42

Is there a way I can get this information without coding something up?


Solution

  • I don't think you can print exactly what you have in the sample, unless you write a stored procedure for it.

    One way to do it (two "selects"):

    1. create table my_table as select ...
    2. \d my_table
    3. select * from my_table