Uso Rails 4.2.3 con un database PostGre. Voglio una colonna nel mio database per memorizzare un numero di millisecondi - nota, NON un timestamp, ma piuttosto una durata in millisecondi. Così ho creato la mia colonna in questo modoIl "valore" 3000002000 "non è compreso nell'intervallo per il tipo intero"
time_in_ms | bigint
Tuttavia, quando vado a memorizzare un valore in Rails, ottengo l'errore sotto
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'
Sembrerebbe il numero, “3.000.002 mila” è più piccolo il valore massimo per la colonna (che sto leggendo è "9223372036854775807"), quindi mi chiedo che altro sta andando storto e come posso aggiustarlo.
Edit: per fornire ulteriori informazioni, nel mio file db/schema.rb, la colonna in questione è descritto questa convenzione ...
create_table "my_object_times", force: :cascade do |t|
...
t.integer "time_in_ms", limit: 8
Edit 2: Ecco l'output di creare tavolo 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
);
controllare una volta il tipo di dati della colonna nel file schema.rb di nuovo? –
Il messaggio di errore suggerisce che la colonna è in realtà un 'int'. Cosa dice il tuo 'schema.rb'? Cosa dice '\ d my_object_times 'da dentro' psql'? –
In una nota a margine, è necessario memorizzare le durate con il tipo di dati 'interval', non un' bigint'. È un intero a 64 bit internamente, come 'bigint', ma se si usa' interval' è più semanticamente utile e si ha accesso a tutti i tipi di operatori a portata di mano. –