-
Notifications
You must be signed in to change notification settings - Fork 297
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
Nano does not roundtrip as part of entity #1304
Comments
The relevant instance here is: -- Database/Persist/Sql/Class.hs line 1258
instance (HasResolution a) => PersistFieldSql (Fixed a) where
sqlType a =
SqlNumeric long prec
where
prec = round $ (log $ fromIntegral $ resolution n) / (log 10 :: Double) -- FIXME: May lead to problems with big numbers
long = prec + 10 -- FIXME: Is this enough ?
n = 0
_mn = return n `asTypeOf` a So, this explains However, SQLite doesn't support numbers with arbitrary position or size. See #1096 for a related issue, and the SQLite's datatype support documentation.
An 8 byte float
(emphasis mine) We can verify this behavior in GHCi:
I'm all ears for ways we can support this better in |
I think a database library should be able to roundtrip the data it stores. (I guess this is an opinion .. ?)
I think the best way to deal with this is either
I'd be happy with either, but we'd need some migration strategy for the second. (Maybe we could have the What are your thoughts on this, @parsonsmatt ? EDIT: Just so you know why I have this opinion: |
Bingo. This is a problem with SQLite's datatype rules. In any database library that tries to support multiple datastores, you run into tensions like these - given that all databases differ on their features, what functionality should a library offer? One extreme is to only support the minimal functionality that is equally shared among all datastores. Another is to support everything nominally and use slow defaults or error on bad implementations. One option is to omit the instance for Switching to the |
What a mess. Then the best we can do is write docs with "This doesn't roundtrip" in the right places, I guess? |
more ideas: |
I don't think this is a good approach - while it would allow for larger
I can be convinced this is a good idea. After all, we don't support Postgresql's MySQL's OK, I am convinced - let's drop
This'll be a breaking change, so would need to go under 2.14 |
Bug Reports
I'm using persistent as part of LTS 16.12 with sqlite.
I have this database definition:
I noticed something really weird when running this in a property test:
output
As you can see, the latitude and logitude are different.
I did some digging already. (If you do so, watch out for this issue.)
So far so good, so it looks like the problem is between sqlite and persistent.
Repro script:
Output:
The text was updated successfully, but these errors were encountered: