I am making a script to audit the tables of a postgres database, for which I need to obtain the names of the tables that are in the database and in this way be able to go through them through an array, since the database it has many tables and I don't want to do it by hand.
Is there a query in postgresql to get the names of the tables that make up the database?
Based on the official PostgreSQL documentation about the information of the database schema , what could be done is to consult the information of the tables stored in
information_schema
since in this there is a table calledtables
in which the name of each table is found that makes up the database. The query would be the following:In this way, the names of the tables that make up the database would be obtained, generating a result that can be iterated in some programming language.
another very useful and proven option; I have the same doubt as you.
or may be
credit to https://stackoverflow.com/questions/769683/show-tables-in-postgresql
Specifically, if what you are looking for is a procedure to perform any spontaneous action with those tables, I usually build a script on the fly with a very easy structure and it is not necessary to create a function, execute it and then delete it.
Using Juan Pinzón's query, the script would be as follows: