mirror of
https://github.com/postgres/postgres.git
synced 2025-07-30 11:03:19 +03:00
Implement IF NOT EXISTS for CREATE SEQUENCE.
Fabrízio de Royes Mello
This commit is contained in:
@ -122,6 +122,24 @@ DefineSequence(CreateSeqStmt *seq)
|
||||
(errcode(ERRCODE_FEATURE_NOT_SUPPORTED),
|
||||
errmsg("unlogged sequences are not supported")));
|
||||
|
||||
/*
|
||||
* If if_not_exists was given and a relation with the same name already
|
||||
* exists, bail out. (Note: we needn't check this when not if_not_exists,
|
||||
* because DefineRelation will complain anyway.)
|
||||
*/
|
||||
if (seq->if_not_exists)
|
||||
{
|
||||
RangeVarGetAndCheckCreationNamespace(seq->sequence, NoLock, &seqoid);
|
||||
if (OidIsValid(seqoid))
|
||||
{
|
||||
ereport(NOTICE,
|
||||
(errcode(ERRCODE_DUPLICATE_TABLE),
|
||||
errmsg("relation \"%s\" already exists, skipping",
|
||||
seq->sequence->relname)));
|
||||
return InvalidOid;
|
||||
}
|
||||
}
|
||||
|
||||
/* Check and set all option values */
|
||||
init_params(seq->options, true, &new, &owned_by);
|
||||
|
||||
@ -210,7 +228,7 @@ DefineSequence(CreateSeqStmt *seq)
|
||||
stmt->options = NIL;
|
||||
stmt->oncommit = ONCOMMIT_NOOP;
|
||||
stmt->tablespacename = NULL;
|
||||
stmt->if_not_exists = false;
|
||||
stmt->if_not_exists = seq->if_not_exists;
|
||||
|
||||
seqoid = DefineRelation(stmt, RELKIND_SEQUENCE, seq->ownerId);
|
||||
Assert(seqoid != InvalidOid);
|
||||
|
Reference in New Issue
Block a user