Comments (6)
For the above thing, you can either edit the code in lib
as a temporary test, or in your own code after you require "pg"
you could probably monkey patch over the numeric initializer
require "pg"
module PG
struct Numeric
def initialize(@ndigits : Int16, @weight : Int16, sign, @dscale : Int16, @digits : Array(Int16))
@sign = Sign.from_value(sign)
p [self, ndigits, weight, sign, dscale, digits] # maybe remove the self part if that also cause the problem
end
end
end
I haven't actually tested that, so there might be some mistakes
from crystal-pg.
Thanks for reporting this. I expect to do a release sometime next week.
from crystal-pg.
Hope you will see this error
from crystal-pg.
@huuhait Can you provide a numeric that has this problem? I tried the number in your text, then two of numbers in your screenshot, and haven't been able to reproduce it yet
require "pg"
def debug(ndigits, weight, sign, dscale, digits)
n = PG::Numeric.new(ndigits.to_i16, weight.to_i16, sign.to_i16, dscale.to_i16, digits.map(&.to_i16))
puts n
puts n.inspect
puts n.to_s
puts n.to_f
n
end
debug 2, -1, 0, 5, [3390, 8000]
debug 2, 0, 0, 1, [595, 8000]
debug 5, 0, 0, 14, [202, 238, 6399, 9999, 9700]
[0.33908, 2, -1, 0, 5, [3390, 8000]]
0.33908
0.33908
0.33908
0.33908
[595.8, 2, 0, 0, 1, [595, 8000]]
595.8
595.8
595.8
595.8
[202.02386399999997, 5, 0, 0, 14, [202, 238, 6399, 9999, 9700]]
202.02386399999997
202.02386399999997
202.02386399999997
202.02386399999997
To get the digits
, weight
, sign
, dscale
, and digits
, one possible way is to add a print here
diff --git i/src/pg/numeric.cr w/src/pg/numeric.cr
index 19e3bcd..aebe970 100644
--- i/src/pg/numeric.cr
+++ w/src/pg/numeric.cr
@@ -34,6 +34,7 @@ module PG
def initialize(@ndigits : Int16, @weight : Int16, sign, @dscale : Int16, @digits : Array(Int16))
@sign = Sign.from_value(sign)
+ p [self, ndigits, weight, sign, dscale, digits]
end
# Returns `true` if the numeric is not a number.
and that should print before the exception. But also if you can get a number you know always does it from a select
query, and can give it to me, I can try and figure it out.
from crystal-pg.
@will i've tested
here is results
value in database is 2566.1918905000002000
Playground: https://play.crystal-lang.org/#/r/a763
from crystal-pg.
Thank you, I can reproduce with that number.
Looking into postgres itself it seems like maybe how they go from numeric to float is to generate a string then parse that string, which seems wasteful, but maybe that's the only way for certain https://github.com/postgres/postgres/blob/32d6287d2eef6b6a4dde07e0513f3e4f321792ad/src/backend/utils/adt/numeric.c#L4306-L4330
Looking into different solutions
from crystal-pg.
Related Issues (20)
- shards update/install/build failing at the crystal-pg step HOT 2
- What versions are supported? HOT 2
- Unhandled exception: cannot insert multiple commands into a prepared statement (PQ::PQError) HOT 3
- Error: no overload matches 'PG::Decoders.array_decoder' with type UUID.class HOT 1
- Connecting to unix socket with url HOT 3
- Shards update broken on Crystal 1.0 HOT 2
- Too many successive queries result in DB::ConnectionLost HOT 4
- Unable to connect to Cockroachdb HOT 2
- New Release 0.23.3? HOT 2
- cockroach db HOT 2
- Proper implementation of `sslmode=verify-full` HOT 2
- Unhandled exception: column "foo" does not exist (PQ::PQError) - How to insert into table without specifying all the columns HOT 1
- Time seems to drop precision when passed in as an arg using at_end_of_day HOT 5
- Tables with upcase symbols not readed HOT 2
- Error: can't cast to JSON::Any
- Add ability to automatically return `TIMESTAMPTZ`->`Time` in the Postgres session's time zone
- Exception sending query with bytea[] binary array type? HOT 2
- Support inserting `PG::Interval` instances HOT 3
- Support for fetching results in the text format
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from crystal-pg.