-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
NUMERIC and DECIMAL support for Sqlite #2887
Comments
Sqlx support for a db only those types that those db supports natively. As you might know sqlite doesn't have a type that you can map decimal too. |
@dragonnn Thanks for the reply! I don't see the rational in not supporting it, since sqlx already supports https://github.com/launchbadge/sqlx/blob/main/sqlx-sqlite/src/type_info.rs#L50-L61 Ref: Sqlite Data Types - Affinity name examples |
The problem is that while The SQLite documentation says the following of the
My primary concern is that "well-formed real literal" is poorly defined, As written, it's distinctly possible that it will accept any decimal value, but truncate it to 15 significant digits and store it as a Looking through the SQLite source, I think this interpretation is correct because it simply reads digits until reaching the sig-fig limit: https://github.com/sqlite/sqlite/blob/4f77a270325fe4a582f93f341516db5e2507b064/src/util.c#L543 It's a little weird because it uses a 64-bit unsigned integer as the significand, but it ultimately returns a We can also see pretty easily using the REPL that a value with a precision higher than 15 significant figures (20 in this case) is rounded off:
Since I fear it would be really dangerous to provide direct mappings as users would be quick to utilize them without taking the time to properly understand their caveats, then open bugs when they encounter rounding errors. It would be a bad idea to have the macros choose these types automatically for the same reason. Honestly, you probably just want to avoid the I've been mulling around the idea of a |
The |
@abonander Thanks for the doc update and helping me understand the rational. |
I'll be working on a proof of concept for that |
@abonander Thank would be nice. Saves a lot of writing FromRow impls :) |
Is your feature request related to a problem? Please describe.
I want to use the
DECIMAL
andNUMERIC
data types on Sqlite, butsqlx-sqlite
does not support it.Describe the solution you'd like
Implementation of
DECIMAL
andNUMERIC
on as supported types, with support forrust_decimal
andbigdecimal
Describe alternatives you've considered
Using
DOUBLE
instead.Using dual columns as
INT
to support scaled decimals instead.Additional context
I have not found an issue or PR on the implementation, but please correct me if I am wrong.
The text was updated successfully, but these errors were encountered: