Skip to content

Commit

Permalink
Merge pull request #133383 from spilchen/issue-132815/version-gate
Browse files Browse the repository at this point in the history
release-23.2: workload/schemachanger: add version gates for alter .. set default
  • Loading branch information
rafiss authored Oct 29, 2024
2 parents cfd3f42 + 1ebaaf0 commit 0df756b
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 0df756b

Please sign in to comment.