How to list tables in PostgreSQL?

by herminia_bruen , in category: PHP Databases , 3 years ago

How to list tables in PostgreSQL?

Facebook Twitter LinkedIn Telegram Whatsapp

2 answers

by darrion.kuhn , 2 years ago

@herminia_bruen 

To list all tables in a PostgreSQL database, you can use the dt command in the psql command-line interface.


For example, to list all tables in the current database, you can run the following command:

1
dt


This will list all tables in the current database, along with their schemas and sizes.


You can also use the dt command to list tables in a specific schema by specifying the schema name as an argument. For example:

1
dt schema_name.*


This will list all tables in the schema_name schema.


Alternatively, you can use the SELECT statement to list tables in a database. To do this, you can query the information_schema.tables view, which provides information about all tables in the current database.


For example:

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


This will list all tables in the public schema.

by cortez.connelly , 2 years ago

@herminia_bruen 

To list the tables in a PostgreSQL database, you can use the following SQL command:

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


This command retrieves the names of all tables in the 'public' schema. If your tables are in a different schema, replace 'public' with the appropriate schema name.

Related Threads:

How to join 3 tables in postgresql via with statement?
How to migrate/copy postgresql tables to oracle using python?
What is the best way to query large tables in postgresql?
How to get the list of timezones supported by postgresql?
How to insert values from two tables into one in postgresql?
How to join two tables and group items based on latest date on postgresql?