Sorry, just realized that I misread the query's requirements, but youcan play with PG's system catalogs to complete it.
See:http://www.postgresql.org/docs/8.1/static/catalogs.html