You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After trying to get it to work for this PR #223 I thought it would be best to do it in a future PR.
The main issue with numeric data is the it's binary format is somewhat complex and quite a bit of effort to implement correctly and finding all the edge cases to test. But, I did some work to make the implementation happen and will add here my work.
I had a very hard time finding info explaining this. I really just looked at open source postgres code and some random forums that talked about it (see links below).
Let's use 12.34567 as an example. It looks like this with bytes when trasnfering in binary
The next two bytes are for the sign. This value can represent not just positive or negative, but also NaN and (+/-)infinite. There are constants to figure out what value means what.
The next two bytes are the decimal scale. This represents where the decimal is placed in the digits we get later. I believe we get 5 because there are 5 digits have the decimal in 12.34567.
With those digits we get 1234567000. We cut off the last 0s to get 1234567. With the decimal_scale of 5, we add the decimal 5 from the left, so 12.34567
Here's some links to sources that kinda explain how I figured this out
After trying to get it to work for this PR #223 I thought it would be best to do it in a future PR.
The main issue with numeric data is the it's binary format is somewhat complex and quite a bit of effort to implement correctly and finding all the edge cases to test. But, I did some work to make the implementation happen and will add here my work.
I had a very hard time finding info explaining this. I really just looked at open source postgres code and some random forums that talked about it (see links below).
Let's use
12.34567
as an example. It looks like this with bytes when trasnfering in binary(note that each line is a UInt8)
The first two bytes represent the number of
Int16
s passed that represents the digits.The next two bytes represent the weight of the numeric value. I am not sure what this is used for. I think it might be 10^
weight
.The next two bytes are for the sign. This value can represent not just positive or negative, but also NaN and (+/-)infinite. There are constants to figure out what value means what.
The next two bytes are the decimal scale. This represents where the decimal is placed in the digits we get later. I believe we get 5 because there are 5 digits have the decimal in
12.34567
.Now, we use the
number_of_digits
above to get the nextnumber_of_digits
Int16. That will represent the digits.With those digits we get
1234567000
. We cut off the last 0s to get1234567
. With thedecimal_scale
of 5, we add the decimal 5 from the left, so12.34567
Here's some links to sources that kinda explain how I figured this out
numeric_send
functionnumeric_recv
functionThe text was updated successfully, but these errors were encountered: