Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

PostgreSQL query to list all table names?

Is there any query available to list all tables in my Postgres DB.

I tried out one query like:

SELECT table_name FROM information_schema.tables                       WHERE table_schema='public'  

But this query returns views also.

How can i get only table names only, not views?

like image 574
jobi88 Avatar asked Feb 06 '13 13:02

jobi88


People also ask

How do I list all tables in PostgreSQL?

To list the tables in the current database, you can run the \dt command, in psql : If you want to perform an SQL query instead, run this: SELECT table_name FROM information_schema.

How do I get a list of tables in a database?

To get a list of the tables in a MySQL database, use the mysql client tool to connect to the MySQL server and run the SHOW TABLES command. The optional FULL modifier will show the table type as a second output column.

How do I view tables in PostgreSQL?

Summary. Use the \dt or \dt+ command in psql to show tables in a specific database. Use the SELECT statement to query table information from the pg_catalog.

How do I get a list of tables in a schema?

The easiest way to find all tables in SQL is to query the INFORMATION_SCHEMA views. You do this by specifying the information schema, then the “tables” view. Here's an example. SELECT table_name, table_schema, table_type FROM information_schema.


2 Answers

What bout this query (based on the description from manual)?

SELECT table_name   FROM information_schema.tables  WHERE table_schema='public'    AND table_type='BASE TABLE'; 
like image 111
vyegorov Avatar answered Sep 19 '22 06:09

vyegorov


If you want list of database

SELECT datname FROM pg_database WHERE datistemplate = false; 

If you want list of tables from current pg installation of all databases

SELECT table_schema,table_name FROM information_schema.tables ORDER BY table_schema,table_name; 
like image 29
Harsh Avatar answered Sep 21 '22 06:09

Harsh