Skip to content

Conversation

@LuccaBitfly
Copy link

This PR adds scanning big.Int values into decimal.Decimal.

The clickhouse-go driver stores certain column types like Int128 as big.Int. Currently, the decimal lib (v1.4.0) returns the error could not convert value '{neg:false abs:[7345112218517]}' to byte array of type 'big.Int' when trying to scan such a column into a decimal.Decimal.

Without this PR, I need a workaround like:

type MyDecimal decimal.Decimal

func (d *MyDecimal) Scan(value any) error {
	switch v := value.(type) {
	case big.Int:
		*d = MyDecimal(decimal.NewFromBigInt(&v, 0))
		return nil
	default:
		return (*decimal.Decimal)(d).Scan(value)
	}
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant