5
Overloading
Several routines with the same name
routine is uniquely identified by a signature:
its name and input parameter types
types of the return value and output parameters are ignored
an appropriate routine is selected during execution based on the argument
types
CREATE OR REPLACE command
for new combination of input parameter types,
creates a new overloaded routine
for existing combination of input parameter types,
changes the corresponding routine, but not the type of the return value
Overloading is the ability to use one and the same name for several routines
(functions or procedures), which differ in types of IN and INOUT
parameters.
In other words, a routine name and types of its input parameters form a
routine signature. When calling a routine, PostgreSQL finds its version that
corresponds to the passed arguments. If an appropriate routine cannot be
determined unambiguously, a runtime error occurs.
A signature, however, does not include:
●
routine type (procedure or function),
●
OUT parameter types,
●
returned value type.
You have to take overloading into account when executing CREATE OR
REPLACE (FUNCTION or PROCEDURE). If input parameter types differ
from those used by already existing routines, a new overloaded routine will
be created, otherwise a matching existing one will be replaced. Besides,
when an existing routine is replaced with the CREATE OR REPLACE
command, its type, OUT parameter types and return value type may not be
changed, but other properties such as the language can be. In some cases,
this means you must delete the routine and create it anew to replace it.
However, doing so requires you to first delete all dependent objects, such as
views, triggers, and other routines (DROP ROUTINE ... CASCADE).