Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Format SqlRational as a decimal ... #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

rickowens
Copy link

... in order to avoid this error when trying to insert a rational
value into the database:

SqlError {seState = "22P02", seNativeError = 7, seErrorMsg = "execute: PGRES_FATAL_ERROR: ERROR: invalid input syntax for type numeric: "603 % 10"\n"}

Apparently, the Show instance isn't good enough. This implementation
technically losses some precision in some cases, but then Haskell's
Rational is larger than PostgreSQL's numeric, so that is fundamentally
unavoidable.

@rickowens
Copy link
Author

cc @MHova @jonkraut

... in order to avoid this error when trying to insert a rational
value into the database:

SqlError {seState = "22P02", seNativeError = 7, seErrorMsg = "execute: PGRES_FATAL_ERROR: ERROR:  invalid input syntax for type numeric: \"603 % 10\"\n"}

Apparently, the `Show` instance isn't good enough. This implementation
technically losses some precision in some cases, but then Haskell's
`Rational` is larger than PostgreSQL's `numeric`, so that is fundamentally
unavoidable.
@rickowens
Copy link
Author

So, to talk a little bit more about this, what is happening here is that I have a value 60.3, represented as a Haskell Rational type. I convert that value into a SqlValue using the SqlRational data constructor, which in turn gets used to fill in a positional argument of a prepared statement. HDBC-postgresql seems to use the information to render a real sql statement, and it appears to use the Convertible SqlValue String instance to implement this rendering, which itself delegates to instance Show Rational, which does not produce a string that can be interpreted as valid sql.

cc @hesselink

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant