Database Reference
In-Depth Information
$$
language plpgsql;
SELECT ambiguous ('parameter');
This is an example of positively atrocious programming that should never occur out-
side of an example of how
not
to write functions. However, PostgreSQL is intelligent
enough to correctly deduce that the contents of the
function
parameter are only
legal in the
VALUES
list. All other occurrences of "parameter" are actually physical
PostgreSQL entities.
We also introduced an optional section to the function. We declare a variable before
the
BEGIN
statement. Variables that appear in this section are valid during the exe-
cution of the function.
Also of note in this function is the
RETURNING id INTO retval
statement. This
feature allows the developer to specify the identity field of the record, and return the
value of that field after the record has been inserted. Our function then returns this
value to the caller as an indicator that the function succeeded and a way to find the
record that has been inserted.