Re: How to list all schema names inside a PostgreSQL database through SQL

From: Виктор Егоров <vyegorov(at)gmail(dot)com>
To: Xiaobo Gu <guxiaobo1982(at)gmail(dot)com>
Cc: pgsql-general(at)postgresql(dot)org
Subject: Re: How to list all schema names inside a PostgreSQL database through SQL
Date: 2012-11-15 12:41:15
Message-ID: CAGnEboigb6ksS+ynekS1dsUYdp+8Gs8KWW9A4YZF5ajMHSxCsA@mail.gmail.com
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

2012/11/15 Xiaobo Gu <guxiaobo1982(at)gmail(dot)com>:
> How can I list all schema names inside a PostgreSQL database through
> SQL, especially thoese without any objects created inside it.

Something like this:
select n.nspname, count(o.oid)
from pg_namespace n
left join pg_class o on n.oid=o.relnamespace
group by 1
order by count(o.oid)>0, 1;

I prefer to query PostgreSQL catalogs.
You can obtain the same information using information_schema queries.

--
Victor Y. Yegorov

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Achilleas Mantzios 2012-11-15 12:43:12 Re: How to list all schema names inside a PostgreSQL database through SQL
Previous Message Xiaobo Gu 2012-11-15 12:31:05 How to list all schema names inside a PostgreSQL database through SQL