Postgres: Get table and field names from a given schema

By Eric Downing. Filed in Programming, SQL  |  
TOP del.icio.us digg

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';

Tags:

Leave a Reply