On 5th of September 2017, Tom Lane committed patch:
Add \gdesc psql command. This command acts somewhat like \g, but instead of executing the query buffer, it merely prints a description of the columns that the query result would have. (Of course, this still requires parsing the query; if parse analysis fails, you get an error anyway.) We accomplish this using an unnamed prepared statement, which should be invisible to psql users. Pavel Stehule, reviewed by Fabien Coelho Discussion: https://postgr.es/m/CAFj8pRBhYVvO34FU=EKb=nAF5t3b++krKt1FneCmR0kuF5m-QA@mail.gmail.com
This is actually pretty interesting thing. Let's assume we have a very complex, and rather slow query, for example:
SELECT *, pg_sleep(1) FROM pg_database;
In my case, with 8 databases, it would take 8 seconds to run. And if all I need is to check what columns are really returned, or what datatypes they use, I can:
=$ \timing Timing IS ON. =$ SELECT *, pg_sleep(1) FROM pg_database \gdesc COLUMN | TYPE ---------------+----------- datname | name datdba | oid encoding | INTEGER datcollate | name datctype | name datistemplate | BOOLEAN datallowconn | BOOLEAN datconnlimit | INTEGER datlastsysoid | oid datfrozenxid | xid datminmxid | xid dattablespace | oid datacl | aclitem[] pg_sleep | void (14 ROWS) TIME: 2.540 ms
And get results immediately (well, in 2.5ms in this case).
I, for one, know that I will be using this a lot, once Pg11 will be released. Thanks guys.