Skip to content

Commit 889f8fc

Browse files
craig[bot]spilchen
andcommitted
Merge #152877
152877: workload/schemachange: fix date parsing error in SET DEFAULT operations r=spilchen a=spilchen 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 Co-authored-by: Matt Spilchen <[email protected]>
2 parents 89aa1f5 + b767d1a commit 889f8fc

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)