Bug #113649 the result of format function truncated when using cursor
Submitted: 16 Jan 2024 10:17 Modified: 16 Jan 2024 11:03
Reporter: Jungyoon Lee Email Updates:
Status: Verified Impact on me:
None 
Category:MySQL Server: DML Severity:S3 (Non-critical)
Version:8.0.31, 8.0.35 OS:Any
Assigned to: CPU Architecture:Any
Tags: cursor, format function

[16 Jan 2024 10:17] Jungyoon Lee
Description:
When using the format function with a large value in conjunction with a cursor, the output string is truncated.

How to repeat:
CREATE PROCEDURE demo(out a varchar(1024))
BEGIN
  DECLARE done INT DEFAULT FALSE;
  DECLARE cur1 CURSOR FOR SELECT format(-1.7976931348623157E+307,256);
  DECLARE CONTINUE HANDLER FOR NOT FOUND SET done = TRUE;
  OPEN cur1;
  read_loop: LOOP
    FETCH cur1 INTO a;
    IF done THEN
      LEAVE read_loop;
    END IF;
  END LOOP;
  CLOSE cur1;
END;

mysql> call demo(@hello);
Query OK, 0 rows affected (0.02 sec)

mysql> select @hello;
+---------------------------------------------------------------+
| @hello                                                        |
+---------------------------------------------------------------+
| -17,976,931,348,623,158,000,000,000,000,000,000,000,000,000,0 |
+---------------------------------------------------------------+
1 row in set (0.01 sec)

mysql> SELECT format(-1.7976931348623157E+307,256);
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| format(-1.7976931348623157E+307,256)                                                                                                                                                                                                                                                                                                                                                                                                                       |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| -17,976,931,348,623,158,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000,000.000000000000000000000000000000 |
+------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
1 row in set (0.01 sec)
[16 Jan 2024 11:03] MySQL Verification Team
Hello Jungyoon Lee,

Thank you for the report and test case.

regards,
Umesh