Describe table is a commonly used query in MySQL. In PostreSQL there isn’t a direct equivalent of this command.

In PostgreSQL command line (pgsql) you can use:

\dt <table_name>
\d <table_name>
\d+ <table_name>

Some cloud provider use a special build or they don’t directly provide pg interface, therefore you can’t use \d \dt commands. You might need an SQL alternative to describe table in PostgreSQL.

select * from INFORMATION_SCHEMA.COLUMNS where table_name = 'tables';

Query above will provide you all columns and column details for a table. The given query will return columns of information_schema.tables table. If you don’t want to describe table in this level of detail you can use following query below:

select column_name, data_type, character_maximum_length, column_default, is_nullable, is_generated from INFORMATION_SCHEMA.COLUMNS where table_name = 'tables';

The query above, can be used for describing table, will show you enough information about a table’s structure.

If you have a question, or addition, please leave a comment below.

A new post everyday, subscribe now and don’t miss it!

Subscribe to our newsletter for cool news

Hi! I’m an IT Specialist

I want to hear from you! I am Working with enterprises for 10+ years to improve their infrastructure and efficiency.

Get in touch with me.

Leave a Reply

Discover more from Empower. Innovate. Transform.

Subscribe now to keep reading and get access to the full archive.

Continue reading