Changed
-
#335: Previously,
sq
didn't handle decimal values correctly. It basically shoved a decimal value into afloat
orstring
and hoped for the best. As is known, floats are imprecise, and so we saw unwanted behavior, e.g.db_type_test.go:194: Error Trace: D:/a/sq/sq/drivers/sqlite3/db_type_test.go:194 Error: Not equal: expected: "77.77" actual : "77.77000000000001"
Now,
sq
uses a dedicatedDecimal
type end-to-end. No precision is lost, and at the output end, the value is rendered with the correct precision.There is a proposal to add decimal support to the Go
database/sql
package. If that happens,sq
will happily switch to that mechanism.- 👉 A side effect of decimal support is that some output formats may now render decimal values differently (i.e. correctly). In particular, Excel output should now render decimals as a number (as opposed to a string), and with the precision defined in the database. Previously, a database
NUMERIC(10,5)
value might have been rendered as100.00
, but will now accurately render100.00000
.
- 👉 A side effect of decimal support is that some output formats may now render decimal values differently (i.e. correctly). In particular, Excel output should now render decimals as a number (as opposed to a string), and with the precision defined in the database. Previously, a database