Skip to content

Commit

Permalink
release-23.2: workload/schemachanger: add version gates for alter .. …
Browse files Browse the repository at this point in the history
…set default

Similar to cockroachdb#128941, we can end up using PGLSN or REFCUSOR in a
mixed-version workload. This adds version gates so we check for
correct errors if we attempt to use them while setting column
defaults.

Fixes: cockroachdb#132815
Release note: None
Release justification: bug fix for a test
  • Loading branch information
spilchen committed Oct 24, 2024
1 parent 104316d commit 1ebaaf0
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions pkg/workload/schemachange/operation_generator.go
Original file line number Diff line number Diff line change
Expand Up @@ -2407,6 +2407,29 @@ func (og *operationGenerator) setColumnDefault(ctx context.Context, tx pgx.Tx) (
stmt.potentialExecErrors.add(pgcode.InvalidTableDefinition)
}

// If the cluster is not finalized, certain column types, such as PGLSN
// and RefCursor, are not yet supported.
isNotFinalized, err := isClusterVersionLessThan(
ctx,
tx,
clusterversion.ByKey(clusterversion.V23_2))
if err != nil {
return nil, err
}
if isNotFinalized {
isPGLSN := datumTyp != nil && (datumTyp.Family() == types.PGLSNFamily ||
(datumTyp.Family() == types.ArrayFamily &&
datumTyp.ArrayContents().Family() == types.PGLSNFamily))
isRefCursor := datumTyp != nil && (datumTyp.Family() == types.RefCursorFamily ||
(datumTyp.Family() == types.ArrayFamily &&
datumTyp.ArrayContents().Family() == types.RefCursorFamily))
stmt.potentialExecErrors.addAll(codesWithConditions{
{code: pgcode.Syntax, condition: isPGLSN || isRefCursor},
{code: pgcode.FeatureNotSupported, condition: isPGLSN || isRefCursor},
{code: pgcode.UndefinedObject, condition: isPGLSN || isRefCursor},
})
}

strDefault := tree.AsStringWithFlags(defaultDatum, tree.FmtParsable)
stmt.sql = fmt.Sprintf(`ALTER TABLE %s ALTER COLUMN %s SET DEFAULT %s`, tableName,
lexbase.EscapeSQLIdent(columnForDefault.name), strDefault)
Expand Down

0 comments on commit 1ebaaf0

Please sign in to comment.