Database Reference
In-Depth Information
AS
$$
BEGIN
RETURN substring(keyfield,starting_point);
END
$$
LANGUAGE plpgsql;
The previous function also demonstrates overloading of the mid function. Overload-
ing is another feature of PostgreSQL functions, which allows for multiple procedures
using the same name, but different parameters. In this case, we first declared the
mid function with three parameters, but in this example, overloading is used to im-
plement an alternative form of the mid function where there are only two paramet-
ers. When the third parameter is omitted, the result will be the string starting from
starting_point and continuing to the end of the input string.
SELECT mid('Kirk L. Roybal',9);
The previous line of code yields the following result:
Roybal
In order to access the function parameters by name, PostgreSQL makes a few edu-
cated guesses depending on the statement. Consider for a moment the following
function:
CREATE OR REPLACE FUNCTION ambiguous(parameter
varchar) RETURNS integer AS $$
DECLARE retval integer;
BEGIN
INSERT INTO parameter (parameter) VALUES
(parameter) RETURNING id INTO retval;
RETURN retval;
END
Search WWH ::




Custom Search