PostgreSQL - Describe Table
Last Updated :
13 Aug, 2024
Unlike MySQL, PostgreSQL does not have a 'DESCRIBE' statement to view table column details. However, PostgreSQL provides several methods to access information about table columns.
In this article, we'll learn two effective ways to Describe Tables in PostgreSQL.
1. Using the pSQL shell
The 'psql' command-line interface in PostgreSQL offers commands to describe table structures. The information on various columns of a table can be achieved by any of the below commands.
Syntax:
\d or \d+
Example:
In this example, we will describe the table city of the sample database, ie, dvdrental:
First, log into the PostgreSQL server using the pSQL shell:

Now shift to the dvdrental database using the below command:
\c dvdrental
Now use the below command to describe the city table:
\d city;
This will result in the below:

The below command can also be used for the same purpose:
\d+ city
Output:

Explanation: The output of '\d city' or '\d+ city' will include columns, types, modifiers, and constraints.
2. Using information_schema
The 'information_schema.columns' catalog contains the information on columns of all tables. To get information on columns of a table, you query the 'information_schema.columns' catalog.
Syntax:
SELECT
table_name,
column_name,
data_type
FROM
information_schema.columns
WHERE
table_name = 'table_name';
Example:
Use the below statement to get information on the film table of the dvdrental database.
Query:
SELECT
table_name,
column_name,
data_type
FROM
information_schema.columns
WHERE
table_name = 'film';
Output:

Explanation: The result set will include columns such as 'table_name', 'column_name', and 'data_type', providing a clear overview of the table structure.
Similar Reads
PostgreSQL - CREATE TABLE In PostgreSQL, the CREATE TABLE statement is used to define a new table within a database. It allows us to specify the table's structure, including column names, data types, and constraints, ensuring data integrity and consistency. Understanding the PostgreSQL table creation process is essential for
5 min read
PostgreSQL - CREATE TABLE AS The CREATE TABLE AS statement in PostgreSQL is a powerful tool used to create a new table and populate it with data returned by a query. This functionality allows you to generate tables on the fly based on query results, which can be very useful for reporting, analysis, and other tasks.Let us better
3 min read
PostgreSQL - ALTER TABLE In PostgreSQL, the ALTER TABLE statement is a powerful and essential tool that allows us to modify the structure of an existing table to meet evolving database needs. With PostgreSQL ALTER TABLE, we can perform various modifications on the table without disrupting the ongoing operations of our datab
6 min read
PostgreSQL - Show Tables In PostgreSQL, viewing tables is an essential task for managing and organizing our database. Although PostgreSQL does not support the SHOW TABLES command like MySQL, it offers alternative commands like \dt in the psql tool, which helps users list all tables within a specific databaseIn this article,
4 min read
PostgreSQL - Create Tables in Python Creating tables in PostgreSQL using Python is an essential skill for developers working with databases. This article will explore the process of creating new tables in the PostgreSQL database using Python.Why Create PostgreSQL Tables with Python?Using Python to create PostgreSQL tables is beneficial
4 min read