aboutsummaryrefslogtreecommitdiff
path: root/src/backend/commands/schemacmds.c
diff options
context:
space:
mode:
authorTom Lane <tgl@sss.pgh.pa.us>2012-10-03 19:47:11 -0400
committerTom Lane <tgl@sss.pgh.pa.us>2012-10-03 19:47:11 -0400
commitfb34e94d214d6767910df47aa7c605c452d11c57 (patch)
tree2e8a4161779f1a32c556b6e4acc5db4cb783db17 /src/backend/commands/schemacmds.c
parent994c36e01d19dece2b0c76fb781e1d08a6e1c814 (diff)
downloadpostgresql-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.c17
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.