diff options
author | Tom Lane <tgl@sss.pgh.pa.us> | 2012-10-03 19:47:11 -0400 |
---|---|---|
committer | Tom Lane <tgl@sss.pgh.pa.us> | 2012-10-03 19:47:11 -0400 |
commit | fb34e94d214d6767910df47aa7c605c452d11c57 (patch) | |
tree | 2e8a4161779f1a32c556b6e4acc5db4cb783db17 /src/backend/commands/schemacmds.c | |
parent | 994c36e01d19dece2b0c76fb781e1d08a6e1c814 (diff) | |
download | postgresql-fb34e94d214d6767910df47aa7c605c452d11c57.tar.gz postgresql-fb34e94d214d6767910df47aa7c605c452d11c57.zip |
Support CREATE SCHEMA IF NOT EXISTS.
Per discussion, schema-element subcommands are not allowed together with
this option, since it's not very obvious what should happen to the element
objects.
FabrÃzio de Royes Mello
Diffstat (limited to 'src/backend/commands/schemacmds.c')
-rw-r--r-- | src/backend/commands/schemacmds.c | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/src/backend/commands/schemacmds.c b/src/backend/commands/schemacmds.c index cd5ce06ca76..e69c86bbabf 100644 --- a/src/backend/commands/schemacmds.c +++ b/src/backend/commands/schemacmds.c @@ -84,6 +84,23 @@ CreateSchemaCommand(CreateSchemaStmt *stmt, const char *queryString) errdetail("The prefix \"pg_\" is reserved for system schemas."))); /* + * If if_not_exists was given and the schema already exists, bail out. + * (Note: we needn't check this when not if_not_exists, because + * NamespaceCreate will complain anyway.) We could do this before making + * the permissions checks, but since CREATE TABLE IF NOT EXISTS makes its + * creation-permission check first, we do likewise. + */ + if (stmt->if_not_exists && + SearchSysCacheExists1(NAMESPACENAME, PointerGetDatum(schemaName))) + { + ereport(NOTICE, + (errcode(ERRCODE_DUPLICATE_SCHEMA), + errmsg("schema \"%s\" already exists, skipping", + schemaName))); + return; + } + + /* * If the requested authorization is different from the current user, * temporarily set the current user so that the object(s) will be created * with the correct ownership. |