I would like to list all tables in the liferay database in my PostgreSQL install. How do I do that?
I would like to execute SELECT * FROM applications; in the liferay database. applications is a table in my liferay db. How is this done?
Here's a list of all my databases:
postgres=# \list
List of databases
Name | Owner | Encoding | Collate | Ctype | Access privileges
-----------+----------+----------+-------------+-------------+-----------------------
liferay | postgres | UTF8 | en_GB.UTF-8 | en_GB.UTF-8 | =Tc/postgres +
| | | | | postgres=CTc/postgres+
| | | | | liferay=CTc/postgres
lportal | postgres | UTF8 | en_GB.UTF-8 | en_GB.UTF-8 |
postgres | postgres | UTF8 | en_GB.UTF-8 | en_GB.UTF-8 |
template0 | postgres | UTF8 | en_GB.UTF-8 | en_GB.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
template1 | postgres | UTF8 | en_GB.UTF-8 | en_GB.UTF-8 | =c/postgres +
| | | | | postgres=CTc/postgres
(5 rows)
postgres=#
If you wish to list all tables, you must use:
to indicate that you want all tables in all schemas. This will include tables in
pg_catalog, the system tables, and those ininformation_schema. There's no built-in way to say "all tables in all user-defined schemas"; you can, however, set yoursearch_pathto a list of all schemas of interest before running\dt.You may want to do this programmatically, in which case
psqlbackslash-commands won't do the job. This is where theINFORMATION_SCHEMAcomes to the rescue. To list tables:BTW, if you ever want to see what
psqlis doing in response to a backslash command, runpsqlwith the-Eflag. eg:so you can see that
psqlis searchingpg_catalog.pg_databasewhen it gets a list of databases. Similarly, for tables within a given database:It's preferable to use the SQL-standard, portable
INFORMATION_SCHEMAinstead of the Pg system catalogs where possible, but sometimes you need Pg-specific information. In those cases it's fine to query the system catalogs directly, andpsql -Ecan be a helpful guide for how to do so.