Simple rails app using Postgres DB, getting 'integer out of range' error when trying to insert 2176968859. Should be an easy fix to the migrations, but I'm not sure. Right now I've got...
create_table :targets do |t| t.integer :tid ... end
Explanation: You've tried to INSERT an integer value into a table that exceeds the range of the underlying integer data type in the specified column. The easiest example of this is when you literally insert a too large value into the database.
An integer column can be null, but '' is an empty string not null. The right syntax for a null integer (or any other sql type) is null .
As opposed to INTEGER and BIGINT data types that can store only whole numbers, the DECIMAL and NUMERIC data types can store rational numbers. They can store 13,1072 digits before the decimal point and up to 16,383 digits after the decimal point.
Here's the magic incantation in your migration when you declare the column:
create_table :example do |t| t.integer :field, :limit => 8 end
The :limit => 8 is the magic in this case as postgres only does signed 4-byte integers when you just say integer. This uses 8-byte signed integers.
What's the question? You are overflowing. Use a bigint if you need numbers that big.
http://www.postgresql.org/docs/8.3/interactive/datatype-numeric.html
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With