15

Possible Duplicate:
Integer out of range on Postgres DB

When my code tries to insert big numbers such as 100001857905525 into a database on heroku, I get the error:

ActiveRecord::StatementInvalid (PGError: ERROR:  integer out of range ) 

The column has been defined as an integer. I use a sqlite3 database. My code is deployed to heroku.

It works fine when I run on localhost. But I get the above error only when I run the code on heroku. Perhaps I can solve the issue by defining the column as a long integer or a double. How do I do this in Ruby/Rails ?

Community
  • 1
  • 1
geeky_monster
  • 8,672
  • 18
  • 55
  • 86
  • 1
    this question has already been asked and answered here http://stackoverflow.com/questions/999570/integer-out-of-range-on-postgres-db – Paul Kaplan Jun 15 '11 at 02:53
  • SQLite is very forgiving (ie all text is text, so no limits on string size, looking at their [datatypes](http://www.sqlite.org/datatype3.html) it appears that ints grow as necessary up to 8 bits), but PostgreSQL (what Heroku uses) is optimized for performance, so you have to find the right type. This is a subtle way to introduce code that works in development but not in production. – Joshua Cheek Jun 15 '11 at 05:12

1 Answers1

41

in your migration, you could try this:

t.integer :uid, :limit => 8

which will produce a 64-bit integer column.

(Just integer with no limit specified will allow, according to the PostgreSQL docs, up to 10 digits.)

Jason Swett
  • 43,526
  • 67
  • 220
  • 351
David
  • 7,310
  • 6
  • 41
  • 63
  • Default value of the column was set to a number more than 8 digits, but it will still work, it is a strange way of setting bigint for the column !! more information is available at: https://moeffju.net/blog/using-bigint-columns-in-rails-migrations – whizcreed Jun 09 '15 at 09:32
  • I was curious what the defaults were. According to [the docs](http://www.postgresql.org/docs/9.1/static/datatype-numeric.html), the max `integer` is 2147483647 (10 digits) and the max `bigint` is 9223372036854775807 (19 digits). The `decimal` type allows up to 131072 digits before the decimal point! – Jason Swett Aug 19 '15 at 19:43