go-pg / pg

Golang ORM with focus on PostgreSQL features and performance
https://pg.uptrace.dev/
BSD 2-Clause "Simplified" License
5.65k stars 401 forks source link

Unable to insert a value of type uint64 into the table column of type DECIMAL(20,0). #1985

Open lakshay2k opened 11 months ago

lakshay2k commented 11 months ago

Issue tracker is used for reporting bugs and discussing new features. Please use Discord or stackoverflow for supporting issues.

Expected Behavior

When a user try to insert a value of type unit64 (for ex: 9383336886908942973) in the table column of type DECIMAL(20,0). The value in the column should be stored as it is without any wrapping to negative value.

Current Behavior

When a user try to insert a value of type unit64 (for ex: 9383336886908942973) in the table column of type DECIMAL(20,0). The value in the column is stored as negative (for ex: -9063407186800608643).

Possible Solution

The library insert function is converting back the uint64 value to int64 and storing it in the database. Possible solution is to simply map uint64 to uint64 values only, which means only allow signed values

Steps to Reproduce

  1. Create a table with column name flow_id with data type as DECIMAL(20,0).
  2. Create a struct having flow_id attribute of type uint64.
  3. Declare a value of above struct type(assign value as 9383336886908942973) and try to insert in the postgres database using *pg.Db.model().insert() function passing the struct variable.
  4. Check in the database, the record will reflect a negative value which should be -9063407186800608643

Context (Environment)

Any IDE running golang Connections with database running postgres

Detailed Description

Possible Implementation