Sorry, just realized that I misread the query's requirements, but you can play with PG's system catalogs to complete it. See: http://www.postgresql.org/docs/8.1/static/catalogs.html
pgsql-general by date:
Соглашаюсь с условиями обработки персональных данных