crystal-pg icon indicating copy to clipboard operation
crystal-pg copied to clipboard

add bigdecimal

Open greenbigfrog opened this issue 6 years ago • 9 comments

Most likely not the optimal solution, but it'll do the job. Require #131 to work. (This will most likely only work on master crystal)


This change is Reviewable

greenbigfrog avatar Jan 21 '18 20:01 greenbigfrog

Attempt of #126 ( @pynixwang )

greenbigfrog avatar Jan 21 '18 20:01 greenbigfrog

directly replace PG:: Numeric with BigDecimal will be better?

pynixwang avatar Jan 22 '18 04:01 pynixwang

@will have you looked at this yet?

greenbigfrog avatar Feb 05 '18 16:02 greenbigfrog

@greenbigfrog thanks. I'm curious though why you said it requires #131?

will avatar Feb 06 '18 22:02 will

It requires a few patches that haven't been released yet (and back when I opened this PR, I had no idea rly how crystal's compiling worked). It only requires following PRs:

https://github.com/crystal-lang/crystal/pull/5582
https://github.com/crystal-lang/crystal/pull/5589
(and maybe https://github.com/crystal-lang/crystal/pull/5525 , not sure if it's required for the functionality of this PR. (I did need it for my project though))

greenbigfrog avatar Feb 06 '18 23:02 greenbigfrog

The new patch has a travis failure @greenbigfrog

 1) PG::Numeric to_big_d
       Invalid BigDecimal: -9.0e-5 (Unexpected 'e' character)
       /usr/share/crystal/src/big/big_decimal.cr:0:9 in 'initialize'
       /usr/share/crystal/src/big/big_decimal.cr:78:5 in 'initialize'
       /usr/share/crystal/src/big/big_decimal.cr:77:3 in 'new'
       /numeric_spec.cr:14:3 in 'bd'
       /usr/share/crystal/src/spec/expectations.cr:0:7 in '~procProc(Nil)'
       /usr/share/crystal/src/spec/methods.cr:255:3 in 'it'
       /usr/share/crystal/src/spec/methods.cr:0:5 in '~procProc(Nil)'
       /usr/share/crystal/src/spec/context.cr:255:3 in 'describe'
       /usr/share/crystal/src/spec/methods.cr:16:5 in 'describe'
       spec/pg/encoder_spec.cr:1:1 in '__crystal_main'
       /usr/share/crystal/src/crystal/main.cr:11:3 in '_crystal_main'
       /usr/share/crystal/src/crystal/main.cr:112:5 in 'main_user_code'
       /usr/share/crystal/src/crystal/main.cr:101:7 in 'main'
       /usr/share/crystal/src/crystal/main.cr:135:3 in 'main'
       __libc_start_main
       ???
       ???

will avatar Feb 11 '18 02:02 will

scientific notation is not support ?

pynixwang avatar Feb 11 '18 03:02 pynixwang

As said, you need the patches I linked in https://github.com/will/crystal-pg/pull/132#issuecomment-363595010 Mainly actually only https://github.com/crystal-lang/crystal/pull/5582 now that I think of it.

greenbigfrog avatar Feb 11 '18 11:02 greenbigfrog

Realized today that this doesn't allow to do math in the query itself (eg -1 * 1.1) since it only passes it in as string (-1 * '1.1')

greenbigfrog avatar Jan 29 '20 18:01 greenbigfrog