tags:

views:

607

answers:

4

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 ...

+2  A: 

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

nsanders
Thanks nsanders. 'bigint' is what I was looking for. Sorry if I phrased the question poorly everyone!
Newy
+1  A: 

Note the range of allowed values for the integer type in http://www.postgresql.org/docs/8.3/interactive/datatype-numeric.html. I think you are going to have to use a bigint, decimal, or double precision.

ysth
A: 

PostgreSQL integers are signed, there is no unsigned datatype - I bet that's your problem.

If you need larger values, use bigint. If bigint also isn't enough, use numeric - but use bigint rather than numeric unless you need the larger size or decimals, since it's much faster.

Magnus Hagander
A: 

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.

Paul Rubel