I need to fetch all tables in a particular Postgres database using node. But not finding any way to achieve that. Is there any way to get that?
For example, suppose I have a database named 'TestDatabase' it contains 4 tables( just assume it can have less or more) Person, Company, Clothes, Animal. I need to get the name of all of them using node.
I am also using node-postgres ('pg') to connect with the database.
As an alternative you can use information_schema
. It is not better then the pg_* objects in the system catalog but is standardized and more portable. Here it is:
select table_schema||'.'||table_name as table_fullname
from information_schema."tables"
where table_type = 'BASE TABLE'
and table_schema not in ('pg_catalog', 'information_schema');
The system objects have been filtered by this expression
table_schema not in ('pg_catalog', 'information_schema')
You can further modify it to only include schemas that you need.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With