I can’t understand what causes a syntax error in a user defined function.
This works:
CREATE FUNCTION func(x INT)
RETURNS INT DETERMINISTIC
RETURN x + 1
SELECT func(10) selects 11.
However, the following fails (at creation time):
CREATE FUNCTION func(x INT)
RETURNS INT DETERMINISTIC
RETURN MAX(x, 1)
It complains about 1) at line 3 (error 1064).
I saw that delimiters can break things for user defined functions, but I’m not using them at all. What’s more, the example in the docs (which uses CONCAT, also with commas) works just fine.
What’s wrong in the failing function syntax?
The function used to determine the greatest of its arguments is called
GREATEST()– notMAX(). The latter is a group-by function which I oftentimes mistakenly use first, too…In short:
GREATEST()is used to determine the maximum value from a list of its arguments whereasMAX()is used to find the maximum (column) value from a result set.