PostgreSQL describe table command

In this post, we will provide the psql command to describe the table in PostgreSQL.

Describe Table - Get detailed information on a table

Enter below command in psql command-line interface:
\d+ table_name
Example:
mydb=# \d+ users
                                           Table "public.users"
  Column  |         Type          | Collation | Nullable | Default | Storage  | Stats target | Description
----------+-----------------------+-----------+----------+---------+----------+--------------+-------------
 id       | integer               |           | not null |         | plain    |              |
 name     | text                  |           | not null |         | extended |              |
 email    | character varying(50) |           |          |         | extended |              |
 country  | character varying(50) |           |          |         | extended |              |
 password | character varying(50) |           |          |         | extended |              |
Indexes:
    "users_pkey" PRIMARY KEY, btree (id)

Show all tables command - Lists all tables in a current database

\dt
Example:
mydb=# \dt
         List of relations
 Schema | Name  | Type  |  Owner
--------+-------+-------+----------
 public | users | table | postgres
(1 row)

References


Comments