PostgreSQL describe table

In this article, we will see PostgreSQL describe table. Which means we will get the table structure in of PostgreSQL table.

We can get the table structure by using meta command select query.

PostgreSQL describe table using meta command:

Syntax:

\d table_name or \d+ table_name

Examples:

postgres=# \d emp Table "public.emp" Column | Type | Collation | Nullable | Default ---------+-----------------------+-----------+----------+--------- empno | integer | | not null | empname | character varying(30) | | | deptno | integer | | | doj | date | | | salary | integer | | not null | Indexes: "emp_pkey" PRIMARY KEY, btree (empno)

postgres=# \d+ emp Table "public.emp" Column | Type | Collation | Nullable | Default | Storage | Stats target | Description ---------+-----------------------+-----------+----------+---------+----------+--------------+------------- empno | integer | | not null | | plain | | empname | character varying(30) | | | | extended | | deptno | integer | | | | plain | | doj | date | | | | plain | | salary | integer | | not null | | plain | | Indexes: "emp_pkey" PRIMARY KEY, btree (empno) Access method: heap

PostgreSQL describe table

PostgreSQL describe table using select query:

Query:

select column_name, data_type, character_maximum_length from INFORMATION_SCHEMA.COLUMNS where table_name = 'table_name';

Example:

Query to describe table ’emp’ in PostgreSQL:

select column_name, data_type, character_maximum_length from INFORMATION_SCHEMA.COLUMNS where table_name = 'emp';

Also watch below video: