EDUCBA Logo

EDUCBA

MENUMENU
  • Explore
    • EDUCBA Pro
    • PRO Bundles
    • Featured Skills
    • New & Trending
    • Fresh Entries
    • Finance
    • Data Science
    • Programming and Dev
    • Excel
    • Marketing
    • HR
    • PDP
    • VFX and Design
    • Project Management
    • Exam Prep
    • All Courses
  • Blog
  • Enterprise
  • Free Courses
  • Log in
  • Sign Up
Home Data Science Data Science Tutorials PostgreSQL Tutorial PostgreSQL Describe Table
 

PostgreSQL Describe Table

Priya Pedamkar
Article byPriya Pedamkar

Updated May 17, 2023

PostgreSQL Describe Table

 

 

Definition of PostgreSQL Describe Table

PostgreSQL describes a table is defined as check the structure of a table, we can describe the structure of a table by using \d and the table name command in PostgreSQL. In PostgreSQL describe table statement is not present like in MySQL instead of describe, we are using \d table name and \d+ table name. Describe table command gives the information of the name of column, data type of column, column modifiers information, index information, and foreign key constraint information.

Watch our Demo Courses and Videos

Valuation, Hadoop, Excel, Mobile Apps, Web Development & many more.

Syntax:

Below is the syntax of describe table:

1. Describe the table using the command

\d name_of_table

Or

\d+ name_of_table

2. Describe the table using information schema

Select name_of_column1, name_of_column2, name_of_column3, …, name_of_columnN from information_schema.columns where condition;

Or

Select * from information_schema.columns where condition;

Parameter:

  • \d: This is a metadata command used to describe table structure. It will give the information of the name of column, data type of column, collation, nullable, and default column.
  • \d+: This is a metadata command used to describe table structure. It will give the information of name of column, data type of column, collation, nullable, storage, stats_target, description, and default column.
  • Name of table: This is defined as the name of the table which we have used to describe structure. We can use any table with metadata and information schema in PostgreSQL.
  • Select: This statement selects the specified column from the information schema columns tables. We can select single as well as multiple tables from the columns table.
  • Name of column: Selecting the name of a column from the columns table in PostgreSQL defines the process of retrieving the column names. It allows us to select a single or multiple tables from the columns table.
  • Information schema: This is defined as the information schema columns table used to select the column from the columns table. It will describe the information of the table.
  • Columns: This is columns table used to describe the table structure in PostgreSQL. Columns table is very important while describing the table in PostgreSQL.
  • Where condition: This condition is used to select the specified table to describe table structure in PostgreSQL. Where condition is an optional parameter while using a columns table in PostgreSQL.

How to Describe Table in PostgreSQL?

  • To describe the table in PostgreSQL, we have no need to provide any privileges to the user, any user can describe the table.
  • Below example shows that we have no need to provide any privilege to describe the table.
  • In below the first example we check the privileges of a user, db_test user doesn’t have any privileges on the database server.
  • In the second example, we are using the db_test user to describe a table, using the db_test user, it’s possible to describe the table in PostgreSQL because we do not need to give any privileges to describe the table.
psql -U postgres
\du
psql -U db_test -d testing
\d+ stud1
  • Basically, we are using the below command to describe the table in PostgreSQL as follows:
\d
\d+
Select * from information_schema.columns;
Select column_name from information_schema.columns where table_name = 'name_of_table';
  • We can use the metadata command and information_schema.columnscatalog table to describe the table in PostgreSQL.
  • We can also use limit options to describe all the table from the information_schema.columnscatalog table. This catalog table is very important to fetch the information related to all the tables.
  • We can also describe the table by using the pg_admin GUI tool.
  • For describing the table in PostgreSQL, we need to connect the server using psql. Also, we can describe the table by using the OS command prompt.

Examples

Below are the example to describe a table.

Example #1

By using \d Command.

Below example shows that describe the table by using the \d command. We have describing the table name as stud1 by using \d command.

Command:

\d stud1

Example #2

By using \d+ Command.

Below example shows that describe the table by using the \d+ command. We are describing the table name as stud1 by using \d+ command.

Command:

\d+ stud1

Example #3

By using OS Command Prompt.

Below example shows that describe the table by using the OS command prompt. We have described the table name as stud1 using the OS command prompt.

Command:

psql -U postgres -d testing -c "\d+ stud1"

Example #4

Single Table by using information_schema.columns Table.

Below example shows that describe a single table by using the information_schema.columns table. We are describing the table name as stud1 by using the information_schema.columns table.

Command:

select * from information_schema.columns where table_name = 'stud1';

Example #5

Multiple Table by using information_schema.columns Table.

Below example shows that describe multiple table by using a columns table. Using information_schema.columns table, we are describing all tables in PostgreSQL.

Command:

select * from information_schema.columns;

Recommended Articles

We hope that this EDUCBA information on “PostgreSQL Describe Table” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

  1. PostgreSQL Compare Strings
  2. PostgreSQL Copy Database
  3. Text Search PostgreSQL
  4. PostgreSQL OID

Primary Sidebar

Footer

Follow us!
  • EDUCBA FacebookEDUCBA TwitterEDUCBA LinkedINEDUCBA Instagram
  • EDUCBA YoutubeEDUCBA CourseraEDUCBA Udemy
APPS
EDUCBA Android AppEDUCBA iOS App
Blog
  • Blog
  • Free Tutorials
  • About us
  • Contact us
  • Log in
Courses
  • Enterprise Solutions
  • Free Courses
  • Explore Programs
  • All Courses
  • All in One Bundles
  • Sign up
Email
  • [email protected]

ISO 10004:2018 & ISO 9001:2015 Certified

© 2025 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

By continuing above step, you agree to our Terms of Use and Privacy Policy.
*Please provide your correct email id. Login details for this Free course will be emailed to you
EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

EDUCBA Login

Forgot Password?

🚀 Limited Time Offer! - 🎁 ENROLL NOW