I’m using Rails 4.2.3 with a PostGre database. I want a column in my database to store a number of milliseconds — note, NOT a timestamp, but rather a duration in milliseconds. So I created my column like so
time_in_ms | bigint
However, when I go to store a value in Rails, I get the below error
ActiveRecord::StatementInvalid (PG::NumericValueOutOfRange: ERROR: value "3000002000" is out of range for type integer
: INSERT INTO "my_object_times" ("time_in_ms", "my_object_id", "created_at", "updated_at") VALUES ($1, $2, $3, $4) RETURNING "id"):
app/controllers/my_objects_controller.rb:31:in `update'
It would seem the number, “3000002000” is smaller than the maximum value for the column (which I’m reading is “9223372036854775807”), so I’m wondering what else is going wrong and how I can fix it.
Edit: To provide additional information, in my db/schema.rb file, the column in question is described thusly ...
create_table "my_object_times", force: :cascade do |t|
...
t.integer "time_in_ms", limit: 8
Edit 2: Here is the output of create table in PSQL
CREATE TABLE my_object_times (
id integer NOT NULL,
first_name character varying,
last_name character varying,
time_in_ms bigint,
created_at timestamp without time zone NOT NULL,
updated_at timestamp without time zone NOT NULL,
name character varying,
age integer,
city character varying,
state_id integer,
country_id integer,
overall_rank integer,
age_group_rank integer,
gender_rank integer
);
int
. What does yourschema.rb
have to say? What does\d my_object_times
say from insidepsql
? – Colchicuminterval
data type, not abigint
. It's a 64-bit integer internally, likebigint
, but if you useinterval
it's more semantically useful and you get access to all sorts of handy operators. – Radiometeorograph