Bug #103202 | Procedure using str_to_date behaving differently as stored function | ||
---|---|---|---|
Submitted: | 5 Apr 2021 7:55 | Modified: | 25 Jul 17:45 |
Reporter: | Geert Vanderkelen | Email Updates: | |
Status: | Closed | Impact on me: | |
Category: | MySQL Server: Documentation | Severity: | S3 (Non-critical) |
Version: | 8.0 | OS: | Any |
Assigned to: | CPU Architecture: | Any | |
Tags: | cast, stored routine, STR_TO_DATE |
[5 Apr 2021 7:55]
Geert Vanderkelen
[5 Apr 2021 8:01]
Geert Vanderkelen
You know, I have been looking at this for the past 1.5h, and when I post it, when I see my own bug report, I just realise that: * Stored procedure uses SELECT which gives a warning for str_to_date failing * Stored function does not use as SELECT, so fails hard * The workaround, doing the `SET @d ...` is following the SELECT-path, so also not failing However.. the HANDLER should have worked? Why is that error not handled the same way? Or is that not possible in a RETURN? Maybe a fact to note in https://dev.mysql.com/doc/refman/8.0/en/return.html ?
[5 Apr 2021 13:46]
MySQL Verification Team
Hi Mr. Vanderkelen, Thank you for your bug report. However, this is not a bug. According to SQL standard, sub-chapter 4.28, stored procedures and functions do not behave the same. However, you could try storing in your DATETIME local variable the same expression that you used in your stored procedure. This will require additional effort on your side. Not a bug.
[5 Apr 2021 13:46]
MySQL Verification Team
Hi Mr. Vanderkelen, Thank you for your bug report. However, this is not a bug. According to SQL standard, sub-chapter 4.28, stored procedures and functions do not behave the same. However, you could try storing in your DATETIME local variable the same expression that you used in your stored procedure. This will require additional effort on your side. Not a bug.
[5 Apr 2021 15:19]
MySQL Verification Team
Hi Mr. Vanderkelen, Your diagnosis is correct. It boils down to the error 1411 and how is it handled when you can run select and when you don't. This is a difference in how stored functions and procedures behave. A better workaround is to use SELECT ..... INTO @local_datetime_variable; Still not a bug, but expected behaviour.
[5 Apr 2021 15:56]
Geert Vanderkelen
I already added a workaround, it is working, that is fine (it is useless in indexing sadly). That's not the really the point of this report. Stored functions allow to declare condition handling with DECLARE .. HANDLER. Quoting the MySQL documentation: https://dev.mysql.com/doc/refman/8.0/en/declare-handler.html: "To ignore a condition, declare a CONTINUE handler for it and associate it with an empty block." That's what I did in the Stored Routine (a function in this case). But apparently, it doesn't work for the statement in the RETURN. This is not mentioned in: * https://dev.mysql.com/doc/refman/8.0/en/condition-handling-restrictions.html * or https://dev.mysql.com/doc/refman/8.0/en/return.html If this is particular thing is documented it in the SQL Standard, then it would be great to maybe mention that "some condition handling might not work"? I find it a bit odd since a function is all about the RETURN.
[6 Apr 2021 12:25]
MySQL Verification Team
Hi Mr. Vanderkelen, We agree with you that this is a good request for documentation update. Verified.
[6 Apr 2021 12:25]
MySQL Verification Team
Correct version.
[5 Aug 2021 13:38]
Stefan Hinz
Adding something like "some condition handling might not work" to the documentation will not be helpful, but rather cause additional confusion, thus rejecting this request.
[25 Jul 17:45]
Stefan Hinz
Posted by developer: No additional feedback was provided. Closing.
[26 Jul 9:37]
MySQL Verification Team
Thank you, Stefan.