Skip to content
This repository was archived by the owner on Jul 12, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions numeric.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,8 @@ func (src *Numeric) AssignTo(dst interface{}) error {
return fmt.Errorf("%d is greater than maximum value for %T", normalizedInt, *v)
}
*v = normalizedInt.Uint64()
case **Numeric:
*v = src
default:
if nextDst, retry := GetAssignToDstType(dst); retry {
return src.AssignTo(nextDst)
Expand Down
4 changes: 3 additions & 1 deletion numeric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,7 @@ func TestNumericAssignTo(t *testing.T) {
var f64 float64
var pf32 *float32
var pf64 *float64
var pNum *pgtype.Numeric

simpleTests := []struct {
src *pgtype.Numeric
Expand Down Expand Up @@ -312,6 +313,7 @@ func TestNumericAssignTo(t *testing.T) {
}{
{src: &pgtype.Numeric{Int: big.NewInt(42), Status: pgtype.Present}, dst: &pf32, expected: float32(42)},
{src: &pgtype.Numeric{Int: big.NewInt(42), Status: pgtype.Present}, dst: &pf64, expected: float64(42)},
{src: &pgtype.Numeric{Int: big.NewInt(42), Status: pgtype.Present}, dst: &pNum, expected: pgtype.Numeric{Int: big.NewInt(42), Status: pgtype.Present}},
}

for i, tt := range pointerAllocTests {
Expand All @@ -320,7 +322,7 @@ func TestNumericAssignTo(t *testing.T) {
t.Errorf("%d: %v", i, err)
}

if dst := reflect.ValueOf(tt.dst).Elem().Elem().Interface(); dst != tt.expected {
if dst := reflect.ValueOf(tt.dst).Elem().Elem().Interface(); !reflect.DeepEqual(dst, tt.expected) {
t.Errorf("%d: expected %v to assign %v, but result was %v", i, tt.src, tt.expected, dst)
}
}
Expand Down