[MDEV-30350] STR_TO_DATE fails to return null in procedure Created: 2023-01-05  Updated: 2023-11-28

Status: Confirmed
Project: MariaDB Server
Component/s: Stored routines
Affects Version/s: 10.5.18
Fix Version/s: 10.4, 10.5, 10.6, 10.11

Type: Bug Priority: Major
Reporter: Anestis Fraganestis Assignee: Alexander Barkov
Resolution: Unresolved Votes: 0
Labels: None
Environment:

Debian 11


Attachments: PNG File mariadb1.png     PNG File mariadb2.png    

 Description   

Calling a simple function which uses STR_TO_DATE twice to safely return a date produces an error while the same code run as a select produces (the expected) warning.

DELIMITER $$
CREATE DEFINER=`root`@`localhost` FUNCTION `safe_date`(`date_str` VARCHAR(30)) RETURNS datetime
    NO SQL
    DETERMINISTIC
return COALESCE(STR_TO_DATE(date_str,'%d/%m/%Y'),STR_TO_DATE(date_str,'%Y-%m-%d'))$$
DELIMITER ;



 Comments   
Comment by Sergei Golubchik [ 2023-02-03 ]

as a workaround use

DELIMITER $$
set statement sql_mode='' for
CREATE FUNCTION safe_date(date_str VARCHAR(30)) RETURNS datetime
    NO SQL
    DETERMINISTIC
return COALESCE(STR_TO_DATE(date_str,'%d/%m/%Y'),STR_TO_DATE(date_str,'%Y-%m-%d'))$$
DELIMITER ;

or remove STRICT_TRANS_TABLES from sql_mode before RETURN in any other way

Comment by Anestis Fraganestis [ 2023-02-03 ]

@Sergei Golubchik... thanx... I will try it.

Generated at Thu Feb 08 10:15:35 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.