Skip to content


Subversion checkout URL

You can clone with
Download ZIP


SQLite3 Decimals being inserted as blobs #2162

justindell opened this Issue · 5 comments

2 participants


Decimals seem to be inserted incorrectly as blobs in sqlite3, and as a result I am unable to do > or < comparisons on decimals. I have reproduced it by doing the following:

rails new decimal_bug
cd decimal_bug/
rails g scaffold my_number amount:decimal

I then created a "my_number" through the UI with an amount of 100.0. After firing up the dbconsole I executed the following:

select *, typeof(amount) from my_numbers where amount > 200;
1|100.0|2011-07-20 01:58:13.119675|2011-07-20 01:58:13.119675|blob

I added a line to the active_record/test/cases/base_test.rb test_numeric_fields test that reproduces the issue:

def test_numeric_fields
m =
:bank_balance => 1586.43,
:big_bank_balance => BigDecimal("1000234000567.95"),
:world_population => 6000000000,
:my_house_population => 3



assert_equal 0, NumericData.where("bank_balance > ?", 2000.0).count


Can you post the create statement that is generated for your table? Also post the select statement for that is being generated?



Here's the create statement from the log:

SQL (0.5ms) INSERT INTO "my_numbers" ("amount", "created_at", "updated_at") VALUES (?, ?, ?) [["amount", #<BigDecimal:10306ac30,'0.5E3',9(18)>], ["created_at", Wed, 20 Jul 2011 01:58:23 UTC +00:00], ["updated_at", Wed, 20 Jul 2011 01:58:23 UTC +00:00]]

The select statement I would like to do is something along the lines of:
SELECT COUNT(*) FROM "my_numbers" WHERE (amount > 200.0)
which is generated by MyNumber.where("amount > ?", 200.0).count


I mean, can you post the create table statement?


CREATE TABLE "my_numbers" ("id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, "amount" decimal, "created_at" datetime, "updated_at" datetime)

@tenderlove tenderlove was assigned

It's worth noting that this is on the master branch. Rails 3.0.9 does not have this issue since it is storing the amounts as either integers or reals, not blobs.

@lsylvester lsylvester referenced this issue from a commit in lsylvester/rails
@al2o3cr al2o3cr Fix several issues with code examples.
- "chaining" layouts with :only/:except removed. See #2162 for discussion.

- double render section now has working examples. Old version implied that calling render once and then falling through would give a DoubleRenderError.

- complete example for layout proc.

- cleaned up a few stray references to layouts ending in bare .erb (no format).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.