All work

Select view

Select search mode

 
50 of

Improve the Error message thrown in case the JS code in stored function returns special number like Infinity, -Infinity or NaN.

Description

In JS function if there is division by zero then JS code returns Infinity which is of type Number. But the resulting datatype in mysql by the JS stored routine is of String type with value 'Infinity'. Hence if such error occurs in some function which has Integer return type and the resulting return value is Infinity we get the error "ERROR 1366 (HY000): Incorrect integer value: 'Infinity' for column 'test(231)' at row 1"

Better to have more meaningful error message maybe like out of range ERROR as we see in case the RETURN type is DOUBLE/FLOAT.

mysql> CREATE FUNCTION test(a INT) RETURNS INTEGER LANGUAGE JS AS $$ return 1/0; $$; Query OK, 0 rows affected (0.02 sec) mysql> SELECT test(1); ERROR 1366 (HY000): Incorrect integer value: 'Infinity' for column 'test(1)' at row 1 mysql> CREATE FUNCTION test2(a INT) RETURNS INTEGER LANGUAGE JS AS $$ return 0/0; $$;; Query OK, 0 rows affected (0.02 sec) mysql> SELECT test2(1); ERROR 1366 (HY000): Incorrect integer value: 'NaN' for column 'test2(1)' at row 1 mysql> CREATE FUNCTION test3(a INT) RETURNS INTEGER LANGUAGE JS AS $$ return -a/0; $$; Query OK, 0 rows affected (0.02 sec) mysql> SELECT test3(4); ERROR 1366 (HY000): Incorrect integer value: '-Infinity' for column 'test3(4)' at row 1

Environment

None

Assignee

Reporter

Needs QA

Priority

Created February 18, 2025 at 9:48 AM
Updated March 25, 2025 at 3:11 PM

Activity

Show:

Flag notifications