Displaying table information with PostgreSQL

01 Aug 2019

In order to quickly and easily display information about a table in PostgreSQL you can follow the steps below.

Firstly, fire up postgres and connect to your database.


\c your_database

Let's say that you have a table in this database called books. We can display information about this table.

\d books

Which will print something like:

      Column         |            Type             | Collation | Nullable | Default 
 id                  | bigint                      |           | not null | 
 title               | character varying           |           |          |
 created_at          | timestamp without time zone |           | not null | 
 updated_at          | timestamp without time zone |           | not null | 

And there you have it. All of the information for the books table. If you require an even more detailed synopsis of your table, you can use the \d+ command instead.