Mysql SUM VARCHAR fields without using CAST

When SUM is used in a query in a field of type VARCHAR in the MySql database, does SUM automatically convert it to a number? I tried this using

  SELECT SUM(parametervalue) FROM table

and it shows that MySql is returning the amount, although I expected to throw an error, since the "parametervalue" field is of type VARCHAR

+4
source share
1 answer

MySQL does a silent conversion for a string in a numeric context. Since it expects a number for sum(), MySQL simply performs the conversion using leading "numbers" from the string. Note that this includes decimal points, a minus sign, and even erepresenting scientific notation. So, '1e6'interpreted as a number.

, 0:

SELECT SUM(parametervalue + 0) FROM table

, cast() , , .

+6

All Articles