diff options
Diffstat (limited to 'src/backend/commands')
-rw-r--r-- | src/backend/commands/extension.c | 1 | ||||
-rw-r--r-- | src/backend/commands/schemacmds.c | 17 |
2 files changed, 18 insertions, 0 deletions
diff --git a/src/backend/commands/extension.c b/src/backend/commands/extension.c index 5712fe19c5c..5aa9bbb19c1 100644 --- a/src/backend/commands/extension.c +++ b/src/backend/commands/extension.c @@ -1376,6 +1376,7 @@ CreateExtension(CreateExtensionStmt *stmt) csstmt->schemaname = schemaName; csstmt->authid = NULL; /* will be created by current user */ csstmt->schemaElts = NIL; + csstmt->if_not_exists = false; CreateSchemaCommand(csstmt, NULL); /* 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. |