EDUCBA

EDUCBA

MENUMENU
  • Blog
  • Free Courses
  • All Courses
  • All in One Bundle
  • Login
Home Data Science Data Science Tutorials PostgreSQL Tutorial Postgres Show Tables

Postgres Show Tables

By Priya PedamkarPriya Pedamkar

Postgres Show Tables

Introduction to Postgres Show Tables

Postgres show tables are defined as list tables from a specific database or specific schema; we can retrieve a table from the command as \dt and using the query to retrieving data from the pg_catalog schema. In MySQL, we can list all tables from the database using the show tables; in PostgreSQL, we can list all the database tables using the \dt command. To show tables from the database, we need to connect to the specific database from which we need to show the tables.

Syntax and Parameters

Below is the syntax of show tables in PostgreSQL.

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

1. Show tables from the database

\c database_name
\dt

OR

\dt+  (Show descriptive output of show tables)

2. Show specific schema tables

\dt shema_name.*

OR

\dt+ shema_name.*   (Show descriptive output of show tables)

3. Show all schema tables

SELECT *(Show all rows from pg_tables) FROM pg_catalog.pg_tables;

OR

\dt *.* (All schema and all tables)

Below is the parameter description syntax of show tables in PostgreSQL

  • Database name: This is defined as the database name used to connect to the database to show all tables from a connected database using the \dt command. We can use any database name to show all tables from the database.
  • \dt: This command is used to show all tables from the connected database.
  • \dt+: This command is used to show all table descriptive output from the connected database.
  • Schema name: We define it to show all tables from the specified schema. We can use any schema name to show all tables from the schema.
  • Select: Select operations are used when we show tables from the catalog schema using pg_tables.
  • Pg_catalog: This schema uses the table name as pg_tables, a catalog schema in PostgreSQL.
  • Pg_tables: This table is a system table that contains the information related to all tables. This contains information like table name, schema name, etc.
  • \dt *.*: This is used when we want to show all the schema tables; first, * define as all schema and second, will define as all tables.
  • *: This is defined as to show all tables from the specified schema. First is the schema name from which we have shown tables, the second * is defined as to show all tables from the specified schema.

How does Show Table work in PostgreSQL?

Below is the working of the show table in PostgreSQL.

It must be present on the database server to show a table from the specified database. The below example shows that we need to connect to the specified database to show the database’s table.

Code:

\dt
\c testing;
\dt

In the above example, we first connected to the default database, i.e., Postgres database; connecting to this database will only display the connected databases’ tables. In the first example, the Postgres database contained no tables to return an empty set. But in the second example, we have connected to the testing database; after connecting to the testing database, it will display all tables from the testing database.

Examples to Implement Postgres Show Tables

Below is an example of show tables in PostgreSQL.

Example #1

Show all tables from the specified database.

The below example shows that it display all tables from the specified database. We have to retrieve all tables from the testing database. We need first connect to the database to show tables.

Code:

\c testing;
\dt

Output:

Postgres Show Tables - 1

Example #2

Show all tables descriptive output from the specified database.

The example below shows the descriptive output from all tables from the specified database. We have to retrieve all tables from the testing database.

Code:

\c testing;
\dt+

Output:

Postgres Show Tables - 2

Example #3

Show a description of the specified table

The below example shows the description of the specified table. We have described the student table.

Code:

\c testing;
\d student;
\d+ student;

Output:

specified table

Example #4

Show all tables from the specified schema.

The below example shows that show all tables from the specified schema. We have to show all tables from the public schema.

Code:

\dt public.*
\dt+ public.*

Output:

table from

Example #5

Show all tables from all schema.

The below example shows that display all tables from all schema.

Code:

\dt *.*
\dt+ *.*

Output:

Postgres Show Tables - 5

Postgres Show Tables - 6

Example #6

Show all tables from the specified schema using the query.

The below example shows that retrieving all tables from the specified schema using the query.

Code:

SELECT * FROM information_schema.tables WHERE table_schema = 'public' ORDER BY table_name;

Output:

specified schema

Recommended Articles

We hope that this EDUCBA information on “Postgres Show Tables” was beneficial to you. You can view EDUCBA’s recommended articles for more information.

  1. PostgreSQL NULLIF | Query Examples
  2. How does PostgreSQL Administration Work
  3. Introduction to PostgreSQL Operators
  4. How IN Operator Works in PostgreSQL
PROGRAMMING LANGUAGES Course
502+ Hours of HD Videos
54 Courses
4 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
SELENIUM Certification Course
57+ Hours of HD Videos
15 Courses
9 Mock Tests & Quizzes
Verifiable Certificate of Completion
Lifetime Access
4.5
IOT System - Design & Develop an IOT System
65+ Hours of HD Videos
7 Courses
Verifiable Certificate of Completion
Lifetime Access
4.5
JENKINS Certification Course
19+ Hours of HD Videos
6 Courses
Verifiable Certificate of Completion
Lifetime Access
4.5
Primary Sidebar
Popular Course in this category
POSTGRESQL Certification Course
 17+ Hour of HD Videos
4 Courses
1 Mock Tests & Quizzes
  Verifiable Certificate of Completion
  Lifetime Access
4.5
Price

View Course
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2023 - 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

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
Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*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?

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more