diff --git a/clients/shared/default_value.go b/clients/shared/default_value.go index 2cb03a4fc..078f0578c 100644 --- a/clients/shared/default_value.go +++ b/clients/shared/default_value.go @@ -39,6 +39,13 @@ func DefaultValue(column columns.Column, dialect sql.Dialect) (any, error) { return sql.QuoteLiteral(extTime.String(column.KindDetails.ExtendedTimeDetails.Format)), nil } case typing.EDecimal.Kind: + if column.KindDetails.ExtendedDecimalDetails.Scale() == 0 { + switch column.DefaultValue().(type) { + case int, int8, int16, int32, int64: + return fmt.Sprint(column.DefaultValue()), nil + } + } + decimalValue, err := typing.AssertType[*decimal.Decimal](column.DefaultValue()) if err != nil { return nil, err diff --git a/clients/shared/default_value_test.go b/clients/shared/default_value_test.go index b88078f1b..6eba23acd 100644 --- a/clients/shared/default_value_test.go +++ b/clients/shared/default_value_test.go @@ -106,20 +106,26 @@ func TestColumn_DefaultValue(t *testing.T) { assert.Equal(t, expectedValue, actualValue, fmt.Sprintf("%s %s", testCase.name, dialect)) } } - { // Decimal value { // Type *decimal.Decimal decimalValue := decimal.NewDecimal(numbers.MustParseDecimal("3.14159")) - col := columns.NewColumnWithDefaultValue("", typing.EDecimal, decimalValue) + col := columns.NewColumnWithDefaultValue("", typing.NewDecimalDetailsFromTemplate(typing.EDecimal, decimal.NewDetails(7, 5)), decimalValue) value, err := DefaultValue(col, redshiftDialect.RedshiftDialect{}) assert.NoError(t, err) assert.Equal(t, "3.14159", value) } + { + // Type int64 + col := columns.NewColumnWithDefaultValue("", typing.NewDecimalDetailsFromTemplate(typing.EDecimal, decimal.NewDetails(5, 0)), int64(123)) + value, err := DefaultValue(col, redshiftDialect.RedshiftDialect{}) + assert.NoError(t, err) + assert.Equal(t, "123", value) + } { // Wrong type (string) - col := columns.NewColumnWithDefaultValue("", typing.EDecimal, "hello") + col := columns.NewColumnWithDefaultValue("", typing.NewDecimalDetailsFromTemplate(typing.EDecimal, decimal.NewDetails(7, 5)), "hello") _, err := DefaultValue(col, redshiftDialect.RedshiftDialect{}) assert.ErrorContains(t, err, "expected type *decimal.Decimal, got string") }