In PostgreSQL you can create a temporary table very easily with:
CREATE TEMPORARY TABLE tmp_foo AS
SELECT bar, baz FROM some_table WHERE ...;
Is there any easy way to get a create statement for that table? I can make queries to get information about the table structure (eg in psql I can use \d) but that doesn't give me a creation statement that I can use.
I would like this so that I can materialize queries in one PostgreSQL database, get the table structure of the query, create that temporary table in another, and then use COPY commands to copy data from one to the other before proceeding.