Skip to content
Related Articles

Related Articles

PostgreSQL – Show Tables
  • Last Updated : 28 Aug, 2020
GeeksforGeeks - Summer Carnival Banner

PostgreSQL does not support the SHOW TABLES statement directly like MySQL does but provides users with an alternative. In this article, we will explore them in detail.

Using Psql Shell:

One way to list all the tables in a database is to use the below command after logging into the database:

Syntax: \dt

Example:

In this example, we will query for the list of all tables in the sample database, ie, dvdrental.

First, log in to the sample database using the below command:



\c dvdrental

Now use the below command to list the tables of the same:

\dt

Output:

Using pg_catalog schema:

Another way to show tables in PostgreSQL is to use the SELECT statement to query data from the PostgreSQL catalog as follows:

Syntax:
SELECT *
FROM pg_catalog.pg_tables
WHERE schemaname != 'pg_catalog' AND 
    schemaname != 'information_schema';

Example:

In this example, we will query for the list of all tables in the sample database, ie, dvdrental.

First, log in to the sample database using the below command:

\c dvdrental

Now runt the below command to list the tables in the database:

SELECT *
FROM pg_catalog.pg_tables
WHERE schemaname != 'pg_catalog' AND 
    schemaname != 'information_schema';

Output:

Attention reader! Don’t stop learning now. Get hold of all the important DSA concepts with the DSA Self Paced Course at a student-friendly price and become industry ready.

My Personal Notes arrow_drop_up
Recommended Articles
Page :