Overloading the Name of a Function

Because Informix® supports routine overloading, you can define more than one function with the same name, but different parameter lists. You might want to overload functions in the following situations:
  • You create a user-defined function with the same name as a built-in function (such as equal( )) to process a new user-defined data type.
  • You create type hierarchies, in which subtypes inherit data representation and functions from supertypes.
  • You create distinct types, which are data types that have the same internal storage representation as an existing data type, but have different names and cannot be compared to the source type without casting. Distinct types inherit support functions from their source types.

For a brief description of the routine signature that uniquely identifies each user-defined function, see Routine Overloading and Routine Signatures.

Examples

Overloaded functions are uniquely identified by the name and the input parameter list. Instead of providing a long unique identifier, it is possible to provide specific name and use it later. The following example illustrates an overloaded function, whose identifier isgetArea, that has the specific names getSquareArea and getRectangleArea:
CREATE FUNCTION getArea
  (i INT DEFAULT 0)
RETURNING INT SPECIFIC getSquareArea;
DEFINE j INT;
LET j = i * i;
RETURN j;
END FUNCTION;

CREATE FUNCTION getArea 
  (i INT DEFAULT 0, j INT DEFAULT 0) 
RETURNING INT SPECIFIC getRectangleArea; 
	DEFINE k INT; 
	LET k = i * j; 
	RETURN k; 
END FUNCTION;
Now you can use the specific name, as in the following example:
GRANT EXECUTE ON SPECIFIC FUNCTION getSquareArea TO informix;
GRANT EXECUTE ON SPECIFIC FUNCTION getRectangleArea TO informix;
Without the specific name, you would need to issue the following:
GRANT  EXECUTE ON FUNCTION getArea (INTEGER) TO informix;
GRANT  EXECUTE ON FUNCTION getArea (INTEGER,INTEGER) TO informix;