When I try to create stored functions with the same names but different signatures:
CREATE FUNCTION `max`(a INT, b INT) RETURNS INT
BEGIN
IF a > b THEN RETURN a; ELSE RETURN b; END IF;
END
CREATE FUNCTION `max`(a DATE, b DATE) RETURNS DATE
BEGIN
IF a > b THEN RETURN a; ELSE RETURN b; END IF;
END
MySQL gives me an error:
FUNCTION max already exists
Do I really have to give distinct names to the functions like max_tinyint
, max_int
, max_date
, max_datetime
, etc.?
Even easier would be if I could create a function that accepts arbitrary types as parameters.
mysql doesn't support function overloading. So the only way for you is to create functions with different names
UPD: and, yes, mysql has GREATEST() function to do what you want
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With