aboutsummaryrefslogtreecommitdiff
path: root/src/backend/parser
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/parser
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/parser')
-rw-r--r--src/backend/parser/gram.y35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/backend/parser/gram.y b/src/backend/parser/gram.y
index 62ff9178286..7feadeac169 100644
--- a/src/backend/parser/gram.y
+++ b/src/backend/parser/gram.y
@@ -1169,6 +1169,7 @@ CreateSchemaStmt:
n->schemaname = $5;
n->authid = $5;
n->schemaElts = $6;
+ n->if_not_exists = false;
$$ = (Node *)n;
}
| CREATE SCHEMA ColId OptSchemaEltList
@@ -1178,6 +1179,40 @@ CreateSchemaStmt:
n->schemaname = $3;
n->authid = NULL;
n->schemaElts = $4;
+ n->if_not_exists = false;
+ $$ = (Node *)n;
+ }
+ | CREATE SCHEMA IF_P NOT EXISTS OptSchemaName AUTHORIZATION RoleId OptSchemaEltList
+ {
+ CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
+ /* One can omit the schema name or the authorization id. */
+ if ($6 != NULL)
+ n->schemaname = $6;
+ else
+ n->schemaname = $8;
+ n->authid = $8;
+ if ($9 != NIL)
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
+ parser_errposition(@9)));
+ n->schemaElts = $9;
+ n->if_not_exists = true;
+ $$ = (Node *)n;
+ }
+ | CREATE SCHEMA IF_P NOT EXISTS ColId OptSchemaEltList
+ {
+ CreateSchemaStmt *n = makeNode(CreateSchemaStmt);
+ /* ...but not both */
+ n->schemaname = $6;
+ n->authid = NULL;
+ if ($7 != NIL)
+ ereport(ERROR,
+ (errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
+ errmsg("CREATE SCHEMA IF NOT EXISTS cannot include schema elements"),
+ parser_errposition(@7)));
+ n->schemaElts = $7;
+ n->if_not_exists = true;
$$ = (Node *)n;
}
;