diff options
Diffstat (limited to 'src/backend/commands/createas.c')
-rw-r--r-- | src/backend/commands/createas.c | 18 |
1 files changed, 15 insertions, 3 deletions
diff --git a/src/backend/commands/createas.c b/src/backend/commands/createas.c index 4c1d909d380..a68d945f2e7 100644 --- a/src/backend/commands/createas.c +++ b/src/backend/commands/createas.c @@ -243,15 +243,27 @@ ExecCreateTableAs(CreateTableAsStmt *stmt, const char *queryString, if (stmt->if_not_exists) { Oid nspid; + Oid oldrelid; - nspid = RangeVarGetCreationNamespace(stmt->into->rel); + nspid = RangeVarGetCreationNamespace(into->rel); - if (get_relname_relid(stmt->into->rel->relname, nspid)) + oldrelid = get_relname_relid(into->rel->relname, nspid); + if (OidIsValid(oldrelid)) { + /* + * The relation exists and IF NOT EXISTS has been specified. + * + * If we are in an extension script, insist that the pre-existing + * object be a member of the extension, to avoid security risks. + */ + ObjectAddressSet(address, RelationRelationId, oldrelid); + checkMembershipInCurrentExtension(&address); + + /* OK to skip */ ereport(NOTICE, (errcode(ERRCODE_DUPLICATE_TABLE), errmsg("relation \"%s\" already exists, skipping", - stmt->into->rel->relname))); + into->rel->relname))); return InvalidObjectAddress; } } |