dolt icon indicating copy to clipboard operation
dolt copied to clipboard

Truncate strings when converting to `double`

Open jycor opened this issue 1 year ago • 0 comments

Whenever a string is converted to a double, MySQL truncates the invalid portions of the string, throws a warning, and continues with rest of the operation. In dolt, we throw errors.

Examples:

mysql> select round('123.456abc');
+---------------------+
| round('123.456abc') |
+---------------------+
|                 123 |
+---------------------+
1 row in set, 1 warning (0.0004 sec)
Warning (code 1292): Truncated incorrect DOUBLE value: '123.456abc'
mysql> select sin('123.456abc');
+---------------------+
| sin('123.456abc')   |
+---------------------+
| -0.8039373685728239 |
+---------------------+
1 row in set, 1 warning (0.0004 sec)
Warning (code 1292): Truncated incorrect DOUBLE value: '123.456abc'
mysql> select log('123.456abc');
+-------------------+
| log('123.456abc') |
+-------------------+
| 4.815884817283264 |
+-------------------+
1 row in set, 1 warning (0.0004 sec)
Warning (code 1292): Truncated incorrect DOUBLE value: '123.456abc'
mysql> select 1 where 1 > '123.456abc';
Empty set, 1 warning (0.0004 sec)
Warning (code 1292): Truncated incorrect DOUBLE value: '123.456abc'
mysql> select sqrt('a');
+-----------+
| sqrt('a') |
+-----------+
|         0 |
+-----------+
1 row in set, 1 warning (0.0010 sec)
Warning (code 1292): Truncated incorrect DOUBLE value: 'a'
mysql> select sqrt('1e-4');
+--------------+
| sqrt('1e-4') |
+--------------+
|         0.01 |
+--------------+
1 row in set (0.0003 sec)

jycor avatar Dec 08 '23 08:12 jycor