Postgresql: Check if Schema Exists?
If you are a total purist or you want to gain some milisecs. I recommend you to make use of postgres native system catalog. One can avoid then nested loop which is caused by calling pg_catalog anyway...
SELECT EXISTS(SELECT 1 FROM information_schema.schemata
WHERE schema_name = 'name');
If you querying pg_namespace directly:
SELECT EXISTS(SELECT 1 FROM pg_namespace WHERE nspname = 'name');
Planer's work is much simpler:
So your own solution was the best.
The following query will tell you whether a schema exists.
SELECT schema_name FROM information_schema.schemata WHERE schema_name = 'name';