Bug #111526 | STR_TO_DATE fails in MySQL stored function with error instead of returning NULL | ||
---|---|---|---|
Submitted: | 21 Jun 2023 19:02 | Modified: | 22 Jun 2023 13:09 |
Reporter: | Lewis Graham | Email Updates: | |
Status: | Verified | Impact on me: | |
Category: | MySQL Server: Stored Routines | Severity: | S3 (Non-critical) |
Version: | 8.0 | OS: | Any |
Assigned to: | CPU Architecture: | Any |
[21 Jun 2023 19:02]
Lewis Graham
[21 Jun 2023 19:09]
Lewis Graham
Additional information. As a workaround, this works. Weird that it works with session variables, but not with declared variables in the function / procedure. IMHO - must be a bug. DROP FUNCTION IF EXISTS JTELWeb.TEST; DELIMITER $$ CREATE FUNCTION IF NOT EXISTS JTELWeb.TEST() RETURNS TIMESTAMP(6) DETERMINISTIC BEGIN SELECT STR_TO_DATE( '2023-06-21', '%Y%m%d' ) INTO @ret_; IF( @ret_ IS NULL ) THEN SELECT STR_TO_DATE( '2023-06-21', '%Y-%m-%d' ) INTO @ret_; END IF; RETURN @ret_; END $$ DELIMITER ; SELECT STR_TO_DATE( '2023-06-21', '%Y%m%d' ); SELECT JTELWeb.TEST(); DROP FUNCTION IF EXISTS JTELWeb.TEST; DELIMITER $$ CREATE FUNCTION IF NOT EXISTS JTELWeb.TEST() RETURNS TIMESTAMP(6) DETERMINISTIC BEGIN SET @ret_ = STR_TO_DATE( '2023-06-21', '%Y%m%d' ); IF( @ret_ IS NULL ) THEN SET @ret_ = STR_TO_DATE( '2023-06-21', '%Y-%m-%d' ); END IF; RETURN @ret_; END $$ DELIMITER ; SELECT STR_TO_DATE( '2023-06-21', '%Y%m%d' ); SELECT JTELWeb.TEST();
[22 Jun 2023 13:09]
MySQL Verification Team
Hi Mr. Graham, Thank you for your bug report. We did not use local variables within the function, but declared variables. Still, behaviour is the same and we got the same results. --------------------------- select test(); ERROR 1411 (HY000): Incorrect datetime value: '2023-06-21' for function str_to_date SELECT STR_TO_DATE( '2023-06-21', '%Y%m%d' ); +---------------------------------------+ | STR_TO_DATE( '2023-06-21', '%Y%m%d' ) | +---------------------------------------+ | NULL | +---------------------------------------+ 1 row in set, 1 warning (0.00 sec) SELECT STR_TO_DATE( '2023-06-21', '%Y-%m-%d' ); +-----------------------------------------+ | STR_TO_DATE( '2023-06-21', '%Y-%m-%d' ) | +-----------------------------------------+ | 2023-06-21 | +-----------------------------------------+ --------------------------- This is now a verified bug. However, it is possible that behaviour is intentionally different for stored routines, so this can be (possibly) changed into a Documentation bug. Thanks for your report.