On 17 Jan 2018, at 5:47 PM, Graham Leggett <minf...@sharp.fm> wrote:

> I need to test whether a database is empty, in other words “createdb” has 
> been executed but no data of any kind appears in that database.
> 
> What is the correct postgresql way to do this?
> 
> Is there a pg_isempty command or equivalent somewhere?

Does this query look right?

db=# select count(s.nspname) from pg_class c join pg_namespace s on s.oid = 
c.relnamespace where s.nspname in ('public');
 count 
-------
     0
(1 row)

It is based on the idea that the database is not empty if there are any class 
entries in the “public” namespace?

Regards,
Graham
—

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to