Database Reference
In-Depth Information
• Default value assignment in the function_identifier() function:
variable_identifier := function_identifier(arguments);
• The SELECT statement in the AVG(amount) function:
SELECT AVG(amount) FROM history;
• The SELECT statement in the getRecords() function:
SELECT getRecords();
Similarly, values are returned with a RETURN statement.
The RETURN expression
As the function ends, the evaluated value of expression will be returned as per the
speciied return type in the CREATE FUNCTION command.
The syntax for the RETURN command is as follows:
CREATE OR REPLACE FUNCTION function_identifier(arguments)
RETURNS TYPE AS
DECLARE
declaration;
BEGIN
statement;
RETURN { variable_name | value }
END;
LANGUAGE 'plpgsql';
Exception handling statements
Programming languages provide an exception handling mechanism to handle errors
and reports for solution analysis. You can implement the RAISE statements to raise
errors and exceptions in the PL/pgSQL function as follows:
RAISE NOTICE ''amount value is small.'';
Error handling will be discussed later in this chapter.
Compound statements
Conditional or looping structures contain statements that are executed on the
evaluation of conditions.
 
Search WWH ::




Custom Search