Sanjay Salunkhe
Sanjay Salunkhe

Reputation: 2733

mysql decimal data type out of range value for column

I am trying to assigne value to decimal column but it is giving me error as "Mysql2::Error: Out of range value for column"

column lattitude(10,7)

As you can see my lattitude column can accept max 10 digits and can accept 7 digits after decimal.

INSERT INTO mytable (lattitude) VALUES (1234.12345);

I want to know why above sql statement giving me an error. As per my research it should not give me an error because it has total 9 digits and 5 digits after decimal.

Upvotes: 1

Views: 1062

Answers (1)

Gordon Linoff
Gordon Linoff

Reputation: 1271231

If your type can accept 7 digits after the decimal place and it can accept 10 digits, then the type can accept only 3 digits before the decimal place.

Your sample data has four digits before the decimal place, so you would need:

latitude decimal(11, 7)

Of course, four digits for a latitude doesn't make sense, at least the way latitudes are defined on the surface of the earth.

Upvotes: 4

Related Questions