1

I was working with pgtype.NumRange. The lower and upper bounds are typed pgtype.Numeric. pgtype.Numeric has the following fields

type Numeric struct {
    Int              *big.Int
    Exp              int32
    Status           Status
    NaN              bool
    InfinityModifier InfinityModifier
}

I guess I'm suppose to able to represent any number using the duo of the Int and Exp fields, but I don't know how to, as big.Int and `int32' are integer types.

From Postgres docs, I can see that numrange can take decimal values in any of lower and upper bounds and data type numeric is a superset of decimal type. So I know I should be able to use decimals, but how can I go about this?

Ercross
  • 519
  • 6
  • 17
  • If you're asking how to initialize an instance of `pgtype.Numeric` then you need not look any further than the _test.go file for the type: https://github.com/jackc/pgtype/blob/master/numeric_test.go – mkopriva Apr 08 '22 at 14:53
  • 2
    Judging from the implementation something like this should work: `x := new(pgtype.Numeric); err := x.Set("3.145")`. – Peter Apr 08 '22 at 14:56
  • @Peter, yeah that works. Thanks. Add your comment as an answer so I can upvote it. – Ercross Apr 09 '22 at 23:50

0 Answers0