2011-01-21 2 views
1
create table test_tables (
id number(38) primary key, 
name varchar2(50), 
age number(5), 
gender varchar2(10), 
point number(5,2) 
); 
insert into test_tables values (1,'name1',20,'male',80.5); 
insert into test_tables values (2,'name2',21,'female',60.5); 
insert into test_tables values (3,'name3',23,'male',90.5); 
insert into test_tables values (4,'name4',19,'male',79.5); 
insert into test_tables values (5,'name5',18,'female',80.5); 

TestTable.sum(:point)の結果は391,
391.5ではないのですか?
私はRDOCをチェックし、いくつかの説明があります。なぜModule.sum(:field)の結果は整数ですか?

The value is returned with the same data type of the column 

は、しかし、私の場合には、「ポイント」の種類は数(5,2)です。
フロートではありませんか?

答えて

3

私はSQLiteに特に慣れていませんが、あなたはcreate table文でDECIMAL型を使用するべきだと思います。詳細:

Active Record SQLite Type Mapping
SQLite Types

は、しかしthis issueに注意してください。 sqlite3ルビドライバは、DECIMALクエリ結果のためにBigDecimalではなくFloatルビオブジェクトを作成するようにしているようです。

関連する問題