In postgres, there is a function pg_typeof which will give the type of a field. Example:
-- Original query
select name, age, descriptions from things LIMIT 1;
-- Meta query
select pg_typeof(name), pg_typeof(age), pg_typeof(descriptions) from things LIMIT 1;
pg_typeof | pg_typeof | pg_typeof
-------------------+-----------+-----------
character varying | integer | text[]
This is a really cool feature. What I am interested in is how to perform a similar technique on an empty table. If there is nothing in the things table, the previous command returns no rows. From the query alone, I want to be able to see the types of the result columns of a query. Notice that what I am asking is not about getting the column types for a table. I already know about information_schema.columns. Envision a query that doesn't map neatly to table rows or a situation with lots a FK constraints. I don't want to have to create dummy data to make the above technique work. If anyone knows of a way to do this (and I know that F# has a library with some magic for doing this), I would be grateful to know. If the question is unclear, please let me know how I could improve it. Thanks.