Bug #35430 "if" example from documentation doesn't work
Submitted: 19 Mar 2008 9:52 Modified: 19 Mar 2008 21:14
Reporter: Daniel Fischer Email Updates:
Status: Closed Impact on me:
None 
Category:MySQL Server: Documentation Severity:S3 (Non-critical)
Version:5.0+ OS:Any
Assigned to: Jon Stephens CPU Architecture:Any

[19 Mar 2008 9:52] Daniel Fischer
Description:
http://dev.mysql.com/doc/refman/5.0/en/if-statement.html

DELIMITER //

CREATE FUNCTION SimpleCompare(n INT, m INT) RETURNS VARCHAR(20)
  BEGIN
    DECLARE s VARCHAR(20);

    IF n > m THEN s = '>';
    ELSEIF n = m THEN s = '=';
    ELSE s = '<'
    END IF;

    s = CONCAT(n, ' ', s, ' ', m);

    RETURN s;
  END //

DELIMITER ;

produces this error:
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near '= '>';

How to repeat:
Just paste the code into the command line client.

Suggested fix:
DELIMITER //

CREATE FUNCTION SimpleCompare(n INT, m INT) RETURNS VARCHAR(20)
  BEGIN
    DECLARE s VARCHAR(20);

    IF n > m THEN SET s = '>';
    ELSEIF n = m THEN SET s = '=';
    ELSE SET s = '<'; 
    END IF;

    SET s = CONCAT(n, ' ', s, ' ', m);

    RETURN s;
  END //

DELIMITER ;
[19 Mar 2008 9:58] Valeriy Kravchuk
Thank you for a bug report.
[19 Mar 2008 10:28] Jon Stephens
This is my goof - I'll handle it.
[19 Mar 2008 21:14] Jon Stephens
Thank you for your bug report. This issue has been addressed in the documentation. The updated documentation will appear on our website shortly, and will be included in the next release of the relevant products.