3

I'm trying to set the column in my database from VARCHAR to INT (values are already in DB)

When doing this action, the following happens (example):

| number (varchar) | number (int |
| 20090911913      > 2147483647  |
| 3009092113       > 2147483647  |

Every number is unique (with VARCHAR value), when setting the column to INT all values become the same (2147483647). Note that all values while being VARCHAR do not contain letters (I checked it)

Now I don't know why this happens, data comes from a CSV and I checked while importing in Sequel Pro if records have a different number (not being 2147483647). In the GUI it shows it's different but when all is imported it will automatically become 2147483647.

What is happening, and how can I prevent this?

Orion
  • 227
  • 1
  • 4
  • 13

2 Answers2

3

When you convert numbers that are outside the range of signed integer type Int, which is from -2147483648.. 2147483647 (i.e. from -231 to 231-1), MySql limits the value to the max value that can be stored in an Int, i.e. 2147483647.

Both values that you show are outside the range representable by an Int. You need to use BigInt form them instead.

Sergey Kalinichenko
  • 675,664
  • 71
  • 998
  • 1,399
1

Try changing the type of the column to BIGINT , this should solve your problem.

The issue here is that the number stored in the VARCHAR is bigger then the maximum number that an INTEGER can hold and therefore out of the range.

Here you can find a document explaining all about Numerical types.

sagi
  • 36,554
  • 5
  • 46
  • 75