eTechtips

Tech Tips and Insights

Postgres: Get table and field names from a given schema

/ ,

I work with a large Postgres install that has many hundreds of schemas. there are times that I need to find a list of tables and fields from a specific schema for a web application that I am developing.

This will return the list of table names within the giving schema:

select relname 
from pg_stat_user_tables 
WHERE schemaname='schema1';

Then to get the given field names from the table that I have chosen:

select column_name 
from information_schema.columns 
where table_name='mytable';

Loading

0 Comments

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.