PostgreSQL

DESCRIBE TABLE PostgreSQL Alternatives

Author: Antonello Zanini
Length: 5 MINS
Type: Guide
Published: 2023-09-12
Intro
See the different ways that PostgreSQL provides to describe a table as you would with the DESCRIBE statement in MySQL.
Tools used in the tutorial
Tool
Description
DbVisualizer
Top rated database management tool and sql client
PostgreSQL
The PostgreSQL database

If you are a MySQL user, you may be familiar with the DESCRIBE statement. That is a synonym of EXPLAIN that gives you information about table structure or query execution plans. Unfortunately, PostgreSQL does not support the DESCRIBE statement. However, you can achieve the same result in other ways.

Let's explore all the DESCRIBE TABLE PostgreSQL alternatives through examples and find out which one is the best.

DESCRIBE TABLE in PostgreSQL

In PostgreSQL, the DESCRIBE statement does not exist. But what does DESCRIBE do in other DBMSs? Time to find out!

Consider the SQL query below:

1
DESCRIBE <table_name>

For example, you could run it against a user table:

Running the MySQL DESCRIBE TABLE query in DbVisualizer.

↑  Running the MySQL DESCRIBE TABLE query in DbVisualizer.

That would produce a description of the columns within the table:

MySQL DESCRIBE TABLE query result.

↑  A zoom in on the MySQL DESCRIBE TABLE query result.

As you can see, the DESCRIBE statement returns a complete description of the columns of the table, including data types, nullability, primary key constraints, and default values.

How to Describe a Table in PostgreSQL

DESCRIBE is a useful feature and even though PostgreSQL does not support it directly, there are three working DESCRIBE TABLE PostgreSQL alternatives. Let’s see them all, digging into their pros and cons!

1. DESCRIBE TABLE in PostgreSQL Using the Command Line

This approach involves using a psql, the terminal-based PostgreSQL front-end.

First, open the terminal and connect to your PostgreSQL server with:

$
psql -U

Replace with the username of the account you want to log in with. psql will then ask you for the user's password. Type it in and press Enter to connect to the database.

Security tip: Since other users can observe executed commands by looking at the CLI command history, you may prefer to avoid typing a password for security reasons by:

  • Setting the password in the PGPASSWORD environment variable
  • Specifying the password to the .pgpass file

Now that you are logged in, connect to your target database.

$
\c database_name

Replace with the name of the database you want to work with.

Next, type one of the commands below to describe a table in psql:

  • \d : Returns all columns, their data types, the tablespace, and any special attributes such as NOT NULL and defaults, as well as associated indexes, constraints, rules, and triggers.
  • \d+ : Same as above but with more information, including comments associated with the columns.

Consider the command below:

$
\d employee

This would return:

The result of the d command.

↑  The result of the "\d" command.

While:

$
\d+ employee

Produces:

The result of the d+ command.

↑  The result of the "\d+" command.

👍 Pros:

  • A lot of information returned, including indexes and foreign key constraints

👎 Cons:

  • CLI might scare non-experienced users
  • Requires several steps
  • Results limited by the visualization capabilities of the CLI

2. DESCRIBE TABLE in PostgreSQL Using a Query

A simple DESCRIBE TABLE PostgreSQL equivalent approach involves running a query against information_schema.columns catalog. This view contains information about all columns of any table in the database.

You can use it to describe a table with the query below:

1
SELECT
2
    column_name,
3
    data_type
4
FROM
5
    information_schema.columns
6
WHERE
7
    table_name = '<table_name>';

Replace with the name of the table you want to describe.

Let’s run the query on the employee table:

Running the query in DbVisualizer.

↑  Running the query in DbVisualizer.

This time, you would get:

The query result.

↑  A zoom in on the query result.

👍 Pros:

  • Straightforward, requires a single query

👎 Cons:

  • No information about indexes and foreign key constraints
  • Limited column information compared to \d+

3. Describe a Table in a Database Client

The easiest way to describe a table in PostgreSQL is by adopting a database client. There are several options on the market but only one supports all PostgreSQL major features, has top user reviews, and is used by NASA. Its name is DbVisualizer!

Download DbVisualizer for free, follow the installation wizard, and set up a PostgreSQL connection.

Now, describing a table becomes a piece of cake. In the dropdown menu on the right, select the database you want to deal with, find the table you are interested in exploring, right-click on it, and select “Open in New Tab:”

Note the Open in New Tab option.

↑  Note the "Open in New Tab" option.

This will open a section with various tabs where you can get visual information about the table details, columns, indexes, foreign keys, and more.

Table description info in DbVisualizer.

↑  Table description info in DbVisualizer.

If that is not enough, you can find extra information about the table as triggers and partitions in the dropdown menu:

Triggers and Partitions dropdowns.

↑  "Triggers" and "Partitions" dropdowns.

Et voilà! The PostgreSQL DESCRIBE TABLE alternatives have no more secrets!

👍 Pros:

  • In-depth, visual information
  • Viable even by non-technical users
  • Takes only a few clicks

👎 Cons:

  • Setting up the client might take some time

Conclusion

Here, you saw everything you should know about describing tables in PostgreSQL. Specifically, you understood what DESCRIBE is in MySQL, saw that PostgreSQL does not support it, and took a look at the PostgreSQL DESCRIBE TABLE alternatives.

As shown above, getting information about a table and its columns, indexes, and foreign key constraints becomes easier with a database client such as DbVisualizer. In particular, DbVisualizer allows you to visually explore a table, from its structure to its data, with just a few clicks. Also, it gives you access to a graph view where you can see the table in an ER-like schema. Try DbVisualizer for free today!

FAQ

Why is the MySQL DESCRIBE table command not present in PostgreSQL?

The MySQL DESCRIBE command is not present in PostgreSQL because the latter DBMS is SQL standards compliant, and DESCRIBE TABLE is not part of the ANSI SQL specification.

What does the DESCRIBE command do in PostgreSQL?

The PostgreSQL DESCRIBE command returns information about a prepared statement or result set. The syntax to use it is:

1
DESCRIBE [ OUTPUT ] <prepared_statement_name> USING [ SQL ] DESCRIPTOR <descriptor_name>

Note that DESCRIBE is specified in the SQL standard.

What is the easiest PostgreSQL describe table approach?

The best way to get complete information about a table in PostgreSQL is to explore it in a fully-featured database client like DbVisualizer.

How to deal with the “did not find any relation named” error?

The "did not find any relation named" error occurs when \d or \d+ cannot find the specified table. To address that issue, you have to check the table name and may need to wrap it with double quotes.

How to list databases in PostgreSQL?

psql is a powerful tool, and in addition to \d to describe a table, it also offers the \l command to get the list of available databases. Check out our article to learn more about how to list databases in Postgres.

DbVisualizer SQL Client.
About the author
Antonello Zanini.
Antonello Zanini
Antonello is a software engineer, and often refers to himself as a technology bishop. His mission is to spread knowledge through writing.
SIGN UP TO RECEIVE THE TABLE'S ROUNDUP
More from the table
TITLE
AUTHOR
Gayatri Sachdeva
TAGS
DBA'S
DronaHQ
TITLE
AUTHOR
Lukas Vileikis
TAGS
MySQL
TITLE
AUTHOR
Bonnie
TAGS
Generation
TITLE
AUTHOR
Bonnie
TAGS
Joins
TITLE
AUTHOR
Igor Bobriakov
TAGS
MySQL
Security
TITLE
AUTHOR
Lukas Vileikis
TAGS
MySQL
Operators
TITLE
AUTHOR
Lukas Vileikis
TAGS
MySQL
NULL
TITLE
AUTHOR
Lukas Vileikis
TAGS
MySQL
Reserved words
TITLE
AUTHOR
Igor Bobriakov
TAGS
Oracle
TITLE
AUTHOR
Antonello Zanini
TAGS
DELETE
TITLE
AUTHOR
Antonello Zanini
TAGS
PostgreSQL
TITLE
AUTHOR
Antonello Zanini
TAGS
PostgreSQL
MySQL
TITLE
AUTHOR
Antonello Zanini
TAGS
PostgreSQL
JSON
TITLE
AUTHOR
Antonello Zanini
TAGS
PostgreSQL
Null
TITLE
AUTHOR
Antonello Zanini
TAGS
Driver
JDBC
ODBC
TITLE
AUTHOR
Antonello Zanini
TAGS
PostgreSQL
Connection
TITLE
AUTHOR
Lukas Vileikis
TAGS
Deduplication
TITLE
AUTHOR
Ochuko Onojakpor
TAGS
SQL
Functions
TITLE
AUTHOR
Lukas Vileikis
TAGS
MySQL
Math
TITLE
AUTHOR
Ochuko Onojakpor
TAGS
Docker
MySQL
TITLE
AUTHOR
Ochuko Onojakpor
TAGS
Views
TITLE
AUTHOR
Lukas Vileikis
TAGS
MySQL
Index
TITLE
AUTHOR
Bonnie
TAGS
BigQuery
TITLE
AUTHOR
Leslie S. Gyamfi
TAGS
Join
TITLE
AUTHOR
Antonello Zanini
TAGS
PostgreSQL
TITLE
AUTHOR
Leslie S. Gyamfi
TAGS
PostgreSQL
TITLE
AUTHOR
Ochuko Onojakpor
TAGS
PrestoDb
TITLE
AUTHOR
Ochuko Onojakpor
TAGS
Ansible
Automation
TITLE
AUTHOR
Antonello Zanini
TAGS
PostgreSQL
TITLE
AUTHOR
Leslie S. Gyamfi
TAGS
PostgreSQL
NoSQL
JSON
TITLE
AUTHOR
Igor Bobriakov
TAGS
Oracle
Data types
TITLE
AUTHOR
TheTable
TAGS
ElasticSearch
TITLE
AUTHOR
Ochuko Onojakpor
TAGS
Security
TITLE
AUTHOR
Lukas Vileikis
TAGS
Language
Design
TITLE
AUTHOR
Lukas Vileikis
TAGS
CRUD
DELETE
TITLE
AUTHOR
Lukas Vileikis
TAGS
CRUD
UPDATE
TITLE
AUTHOR
Lukas Vileikis
TAGS
CRUD
SELECT
TITLE
AUTHOR
Lukas Vileikis
TAGS
CRUD
INSERT
TITLE
AUTHOR
Lukas Vileikis
TAGS
MySQL
TITLE
AUTHOR
Leslie S. Gyamfi
TAGS
PostgreSQL
TITLE
AUTHOR
TheTable
TAGS
Bug
TITLE
AUTHOR
Lukas Vileikis
TAGS
MySQL
Daemon
TITLE
AUTHOR
Lukas Vileikis
TAGS
MySQL
Partitions
TITLE
AUTHOR
Leslie S. Gyamfi
TAGS
Migration
MySQL
PostgreSQL
TITLE
AUTHOR
Antonello Zanini
TAGS
PostgreSQL
hstore
TITLE
AUTHOR
TheTable
TAGS
SQL
TITLE
AUTHOR
Igor Bobriakov
TAGS
SQL server
Security
TITLE
AUTHOR
Ochuko Onojakpor
TAGS
Visualize
TITLE
AUTHOR
TheTable
TAGS
MySQL
TITLE
AUTHOR
Lukas Vileikis
TAGS
SQL
Security
TITLE
AUTHOR
Antonello Zanini
TAGS
PostgreSQL
TITLE
AUTHOR
TheTable
TAGS
PostgreSQL
Docker
TITLE
AUTHOR
Antonello Zanini
TAGS
PostgreSQL
TITLE
AUTHOR
Lukas Vileikis
TAGS
MySQL
Connection
TITLE
AUTHOR
Lukas Vileikis
TAGS
Performance
TITLE
AUTHOR
Lukas Vileikis
TAGS
Security
TITLE
AUTHOR
Antonello Zanini
TAGS
Columns
TITLE
AUTHOR
Ochuko Onojakpor
TAGS
Performance
TITLE
AUTHOR
Ochuko Onojakpor
TAGS
SQL
TITLE
AUTHOR
Lukas Vileikis
TAGS
Performance
Indexes
TITLE
AUTHOR
Lukas Vileikis
TAGS
MySQL
Subquery
TITLE
AUTHOR
Lukas Vileikis
TAGS
Performance
TITLE
AUTHOR
Lukas Vileikis
TAGS
ACID
TITLE
AUTHOR
Lukas Vileikis
TAGS
ALTER TABLE
TITLE
AUTHOR
TheTable
TAGS
MySQL
Ports
TITLE
AUTHOR
Lukas Vileikis
TAGS
MySQL
Security
TITLE
AUTHOR
Lukas Vileikis
TAGS
ACID
MySQL
Security
TITLE
AUTHOR
Antonello Zanini
TAGS
BLOB
TITLE
AUTHOR
TheTable
TAGS
Foreign Key
PostgreSQL
TITLE
AUTHOR
Leslie S. Gyamfi
TAGS
PostgreSQL
Concurrency
TITLE
AUTHOR
Lukas Vileikis
TAGS
Security
Encryption
TITLE
AUTHOR
Lukas Vileikis
TAGS
Security
TITLE
AUTHOR
Bonnie
TAGS
Security
PostgreSQL
TITLE
AUTHOR
Antonello Zanini
TAGS
Subquery
TITLE
AUTHOR
Antonello Zanini
TAGS
Transactions
TITLE
AUTHOR
Ochuko Onojakpor
TAGS
Data structures
TITLE
AUTHOR
Antonello Zanini
TAGS
MySQL
TITLE
AUTHOR
Lukas Vileikis
TAGS
SSH
TITLE
AUTHOR
Antonello Zanini
TAGS
Stored procedure
MySQL
TITLE
AUTHOR
Antonello Zanini
TAGS
Triggers
TITLE
AUTHOR
Igor Bobriakov
TAGS
Microsoft SQL Server
Optimization
TITLE
AUTHOR
Bonnie
TAGS
PostreSQL
TITLE
AUTHOR
Ochuko Onojakpor
TAGS
Reusable queries
TITLE
AUTHOR
Antonello Zanini
TAGS
BIG Data
TITLE
AUTHOR
Lukas Vileikis
TAGS
MySQL
Security
TITLE
AUTHOR
TheTable
TAGS
Beginner
SQL
TITLE
AUTHOR
Ochuko Onojakpor
TAGS
CRUD
SQL Transactions
TITLE
AUTHOR
Lukas Vileikis
TAGS
MySQL
Security
TITLE
AUTHOR
Antonello Zanini
TAGS
PostgreSQL
JSON
TITLE
AUTHOR
Lukas Vileikis
TAGS
MySQL
InnoDB
ibdata1
TITLE
AUTHOR
Lukas Vileikis
TAGS
MySQL
TITLE
AUTHOR
Scott A. Adams
TAGS
Filter
TITLE
AUTHOR
Scott A. Adams
TAGS
SQLite
TITLE
AUTHOR
Scott A. Adams
TAGS
Excel
Export
TITLE
AUTHOR
Scott A. Adams
TAGS
ERD
Join

The content provided on dbvis.com/thetable, including but not limited to code and examples, is intended for educational and informational purposes only. We do not make any warranties or representations of any kind. Read more here.