Skip to content

Commit

Permalink
createsequence
Browse files Browse the repository at this point in the history
  • Loading branch information
jayshrivastava committed Nov 25, 2020
1 parent b8210c7 commit 153605e
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion pkg/workload/schemachange/operation_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -364,7 +364,6 @@ func (og *operationGenerator) createSequence(tx *pgx.Tx) (string, error) {
return "", err
}

ifNotExists := og.randIntn(2) == 0
schemaExists, err := schemaExists(tx, seqName.Schema())
if err != nil {
return "", err
Expand All @@ -374,6 +373,14 @@ func (og *operationGenerator) createSequence(tx *pgx.Tx) (string, error) {
return "", err
}

// If the sequence exists and an error should be produced, then
// exclude the IF NOT EXISTS clause from the statement. Otherwise, default
// to including the clause prevent all pgcode.DuplicateRelation errors.
ifNotExists := true
if sequenceExists && og.produceError() {
ifNotExists = false
}

codesWithConditions{
{code: pgcode.UndefinedSchema, condition: !schemaExists},
{code: pgcode.DuplicateRelation, condition: sequenceExists && !ifNotExists},
Expand Down

0 comments on commit 153605e

Please sign in to comment.