How to list tables in PostgreSQL?

by herminia_bruen , in category: PHP Databases , 9 months ago

How to list tables in PostgreSQL?

Facebook Twitter LinkedIn Telegram Whatsapp

1 answer

by darrion.kuhn , 3 months 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.