-
Notifications
You must be signed in to change notification settings - Fork 549
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
BigDecimal returned from SELECT on decimal column results in value 0 on INSERT #714
Comments
May be resolved by #563, where the SELECT is returning an Integer because there are zero decimal places. On the subsequent INSERT the data is getting lost. |
I have the same issue while importing data form another database. Take a look at #722. |
I believe I'm experiencing this issue as well. For example, a value stored in the |
Please try mysql2 gem version 0.4.3 and let me know if this is resolved? |
I apologize for the delay. I am still seeing this issue. I uninstalled 0.4.2 and specifically installed 0.4.3. This is the object I'm receiving from the |
That data looks suspiciously invalid, doesn't it. |
@casrep what issue are you talking about? It seems we are loosing the focus. This issue is about the problem that performing an INSERT with a BigDecimal parameter results in inserting a 0 into the target table, and this was happening because there where no code in the library to treat the BigDecimal in INSERT statement (issue resolved in 0.4.3, see #722). You are instead complaining about the fact that a column with a value of 7.20 is read into a BigInteger having a value of 0.72E1. Let me allow to notice that 7.20 and 0.72E1 are exactly the same number (@sodabrew what seems suspicious?), and that, as far as I can see, this behavior is directly related to the implementation of the BigInteger class, and not to the mysql2 library, see below
Thus I can't understand what is bothering you! |
Thank you for the larger explanation, I misread the followup. @lhz Thanks again for reporting the issue and @mperrando for providing a PR to fix it. @lhz could you also confirm that this works for you now? |
I have a script to copy rows from a table in one database to an identical table in another. The table has 4 columns, one of which is of type
decimal(15, 0)
.The code to copy a batch of rows looks like this:
The value of the decimal column will be returned as a
BigDecimal
object. When including this object in the arguments passed toexectue
on the prepared insert statement, this always results in the value0
for that column in the row inserted, regardless of the actual value.I can circumvent the issue by casting the BigDecimal to Integer before insertion (or by changing the column type to integer, but I don't have the luxury of changing the schema in this case). Still, it seems contraintuitive that you can not directly insert the same value you got out of a select on the same column type.
The text was updated successfully, but these errors were encountered: