diff --git a/lib/debezium/schema.go b/lib/debezium/schema.go index db9bcbb52..c4d0d3dde 100644 --- a/lib/debezium/schema.go +++ b/lib/debezium/schema.go @@ -61,8 +61,12 @@ type Field struct { Parameters map[string]any `json:"parameters"` } +func (f Field) Scale() (int32, error) { + return maputil.GetInt32FromMap(f.Parameters, "scale") +} + func (f Field) GetScaleAndPrecision() (int32, *int32, error) { - scale, scaleErr := maputil.GetInt32FromMap(f.Parameters, "scale") + scale, scaleErr := f.Scale() if scaleErr != nil { return 0, nil, scaleErr } diff --git a/lib/typing/decimal/details.go b/lib/typing/decimal/details.go index dd348c9b6..f48ee485b 100644 --- a/lib/typing/decimal/details.go +++ b/lib/typing/decimal/details.go @@ -2,6 +2,7 @@ package decimal import ( "fmt" + "log/slog" ) const ( @@ -17,6 +18,13 @@ type Details struct { } func NewDetails(precision int32, scale int32) Details { + if precision == 0 { + // MySQL, PostgreSQL, and SQLServer do not allow a zero precision, so this should never happen. + // Let's log if we observe it happening, and if we don't see it in the logs then we can use zero as the + // [PrecisionNotSpecified] value and change precision to a uint16. + slog.Error("Decimal precision is zero") + } + if scale > precision && precision != PrecisionNotSpecified { // Note: -1 precision means it's not specified.