[MDEV-19087] RETURN can't be used right after BEGIN Created: 2019-03-29  Updated: 2019-03-29  Resolved: 2019-03-29

Status: Closed
Project: MariaDB Server
Component/s: Data Definition - Procedure, PL/SQL, Stored routines
Affects Version/s: 10.1.38
Fix Version/s: N/A

Type: Bug Priority: Major
Reporter: Geoff Montee (Inactive) Assignee: Unassigned
Resolution: Not a Bug Votes: 0
Labels: None


 Description   

In a stored function, RETURN can't be used right after BEGIN.

For example, this fails:

DELIMITER //
 
CREATE FUNCTION trust_me(x INT)
RETURNS INT
DETERMINISTIC
READS SQL DATA
BEGIN
   RETURN (x) //
END //
 
DELIMITER ;

With the non-sensical "empty string" error message:

ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '' at line 6

https://mariadb.com/kb/en/library/basic-sql-debugging/#interpreting-the-empty-error

But it works just fine if you remove the BEGIN/END. For example:

CREATE FUNCTION trust_me(x INT)
RETURNS INT
DETERMINISTIC
READS SQL DATA
   RETURN (x);



 Comments   
Comment by Elena Stepanova [ 2019-03-29 ]

It is not BEGIN/RETURN problem. You're using a wrong delimiter after RETURN, it should be

DELIMITER //
 
CREATE FUNCTION trust_me(x INT)
RETURNS INT
DETERMINISTIC
READS SQL DATA
BEGIN
   RETURN (x);
END //
 
DELIMITER ;

Comment by Geoff Montee (Inactive) [ 2019-03-29 ]

Ah, that makes sense. I expected it was user error in some way. Thanks!

Generated at Thu Feb 08 08:48:58 UTC 2024 using Jira 8.20.16#820016-sha1:9d11dbea5f4be3d4cc21f03a88dd11d8c8687422.