1

\d does not seem to work except for a table in PostgreSQL.

I want to be able to retrieve the equivalent of \d <table>, but for a SELECT query.

For example, I would like to say:

\d (SELECT statement) AS table2

where the SELECT statement might contain JOINs and so on

just like in TimesTen:

desc  (SELECT .. FROM ... WHERE ...)

gives column info like name, type, and length

I can use \pset footer on or --expanded but it doesn't give data type and length.

2
  • This is not possible in psql. Some GUI clients offer this though Commented Nov 10, 2014 at 15:22
  • GUI can fetch this from ODBC, but I need it in psql Commented Nov 10, 2014 at 16:45

1 Answer 1

2

Do you mind doing it inside a transaction?

begin;
create table x as select * from t with no data;
\d x
                 Table "public.x"
 Column |            Type             | Modifiers 
--------+-----------------------------+-----------
 t      | timestamp without time zone | 

rollback;
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.