begriffs / pg_rational

Precise fractional arithmetic for PostgreSQL
MIT License
233 stars 14 forks source link

update example to match current Postgres behavior #25

Closed JaoodxD closed 1 year ago

JaoodxD commented 1 year ago

Fix example of using rational sequence. Not working without explicitly casting bigint to rational.

begriffs commented 1 year ago

Thanks for the update, Maksym!

Two other questions:

JaoodxD commented 1 year ago

Thanks for the update, Maksym!

Two other questions:

  • Did you run through the other examples in the README as well?

Yes, everything else works fine.

  • Can you also check whether the test suite passes on your version of Postgres?

Just passed through test cases.
Here is the output. pg_rational_test.txt

If it's necessary my current version of PG is 14.6

begriffs commented 1 year ago

As I'm thinking about this again, I realize that going through float is an inefficient route.

What we should be doing is using the rational_embed() code path: https://github.com/begriffs/pg_rational/blob/master/pg_rational.c#L217

Ideally put it behind a new rational_in_bigint() function that tests that the bigint is actually within range for the numerator like this: https://github.com/begriffs/pg_rational/blob/master/pg_rational.c#L87-L90 Then add a new cast for bigint, similar to the one for float: https://github.com/begriffs/pg_rational/blob/master/pg_rational--0.0.2.sql#L56-L58

Is this something you feel you have the energy to contribute?

begriffs commented 1 year ago

Nevermind, I found a simpler approach: cast nextval through integer and mark the sequence as integer type.