SELECT EXISTS(SELECT 1 FROM information_schema.schemata WHERE schema_name = ‘data_2014_shanxi‘);
SELECT EXISTS(SELECT 1 FROM pg_namespace WHERE nspname = ‘data_2014_shanx‘);
两种方式都可以,第二个更有效率一些。
详细分析见:
http://*.com/questions/7016419/postgresql-check-if-schema-exists
创建时可以这样,可以多次调用,确保创建成功:
CREATE SCHEMA IF NOT EXISTS data_2014_shanx AUTHORIZATION postgres;