1

I have a table called "User_details" in my Postgres database with a column as "Mobile_no" with data type as Integer.

Now when I try inserting an integer value of length 10, I get the following error

ERROR:  integer out of range

I know this can be resolved if i set the data type to bigint or may be even numeric(10,0) but i want to use Int as the data type.

Any possible solution to set the length of an Integer column in Postgres?

3
  • you can not store a value bigger than 2147483647 in an integer column. Switching to bigint is your only choice Commented Mar 14, 2018 at 12:20
  • 3
    There is no such thing as the "length" of an integer, only the maximum value it can store. And that is 2147483647 Commented Mar 14, 2018 at 12:24
  • @a_horse_with_no_name got it. thanks bud :) Commented Mar 14, 2018 at 12:25

1 Answer 1

1

On PostgreSQL an integer type can hold values between -2147483648 and +2147483647 so if the value to insert is "greater than" there is no way to store it on database, only by modifying the data type for example to bigint you will be able to store greater values (bigint can hold values between -9223372036854775808 to +9223372036854775807).

Please check https://www.postgresql.org/docs/current/static/datatype-numeric.html

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.