Skip to content

Commit b767d1a

Browse files
committed
workload/schemachange: fix date parsing error in SET DEFAULT operations
The schemachange workload could generate invalid SQL when testing type mismatches, causing parse errors instead of expected type mismatch errors. Fix by always using explicit type casting in SET DEFAULT statements. Fixes: #152572 Release note: None Epic: None
1 parent fbc73a7 commit b767d1a

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

pkg/workload/schemachange/operation_generator.go

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2530,8 +2530,11 @@ func (og *operationGenerator) setColumnDefault(ctx context.Context, tx pgx.Tx) (
25302530
}
25312531

25322532
strDefault := tree.AsStringWithFlags(defaultDatum, tree.FmtParsable)
2533-
stmt.sql = fmt.Sprintf(`ALTER TABLE %s ALTER COLUMN %s SET DEFAULT %s`,
2534-
tableName.String(), columnForDefault.name.String(), strDefault)
2533+
// Always use explicit type casting to ensure consistent behavior and avoid parse errors.
2534+
// When the types don't match, this will produce the expected DatatypeMismatch error.
2535+
// When the types do match, the cast is harmless and makes the intent explicit.
2536+
stmt.sql = fmt.Sprintf(`ALTER TABLE %s ALTER COLUMN %s SET DEFAULT %s::%s`,
2537+
tableName.String(), columnForDefault.name.String(), strDefault, datumTyp.SQLString())
25352538
return stmt, nil
25362539
}
25372540

0 commit comments

Comments
 (0)