PostgreSQL – How to List all Tables
To list all the tables in a PostgreSQL database, you can query the information_schema
database which contains metadata about all the tables and other objects in the database.
Below is the SQL query you can use to show all the tables:
SELECT table_name
FROM information_schema.tables
WHERE table_schema = 'public';
This query will retrieve the names of all tables in the ‘public’ schema. If your tables are located in a different schema, you can replace 'public'
with the appropriate schema name.
You can also use the pg_tables
system catalog table to list all tables in the current database.
Here’s an example query to use the pg_tables
catalog:
SELECT tablename
FROM pg_tables
WHERE schemaname = 'public';
This query retrieves the names of all tables in the ‘public’ schema. You can replace 'public'
with the appropriate schema name if your tables are located in a different schema.