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.



Leave a Reply