CopyFrom
issue
#359
Labels
No Label
bug
critical
duplicate
enhancement
epic
help wanted
in progress
invalid
low priority
question
rebase
v1
v5
wontfix
Copied from Github
Kind/Breaking
Kind/Bug
Kind/Documentation
Kind/Enhancement
Kind/Feature
Kind/Security
Kind/Testing
Priority
Critical
Priority
High
Priority
Low
Priority
Medium
Reviewed
Confirmed
Reviewed
Duplicate
Reviewed
Invalid
Reviewed
Won't Fix
Status
Abandoned
Status
Blocked
Status
Need More Info
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
No due date set.
Dependencies
No dependencies set.
Reference: cerc-io/go-ethereum#359
Loading…
Reference in New Issue
Block a user
No description provided.
Delete Branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
In v4 the
CopyFrom
mode usesstrconv.ParseFloat
in order to converttransaction.Value
andaccount.Balance
to a format that can be loaded by the binary lib/pq driver using theCopyFrom
support. This doesn't overflow, but it does cause incorrect values to be inserted into the database for very large values ofBalance
andValue
due to loss of precision during the conversion.In v5 I foolishly switched to
strconv.ParseUint
, and while this doesn't have precision issues it simply overflows at very largeBalance
andValue
.We can't format as a string (the obvious choice) because it results in the below error:
ERROR: insufficient data left in message (SQLSTATE 08P01)
This is also telling of a deficiency in our unit tests which is easily addressed by using large account balances in our mock data, will fix this as this missing coverage is entirely on me.
The direct write mode and sql/csv file write mode is unaffected in either version because the string format is used there without issue.
Having trouble chasing down any solution so tried some shots in the dark:
Tried implementing a custom Scanner/Valuer interface for a big.Int e.g.
But this doesn't work, get
SQLSTATE 57014
error e.g.ERROR: COPY from stdin failed: cannot convert {{false [1000]}} to Numeric (SQLSTATE 57014)
Tried casting the strings to []uint8 but that throws
ERROR: COPY from stdin failed: cannot convert [49 48 48 48] to Numeric (SQLSTATE 57014)
Tried checking and ensuring no null/newline characters are present in the string (there aren't), so that didn't fix anything either.
I'm not confident there is a solution using the binary CopyFrom mode used by lib/pq.
This change uses a pgx-compatible Numeric datatype which is backed by a shopspring.Decimal.
d2bfae64eb
Thanks for the quick fix on this @telackey !