There are several ways to create function with PL/pgSQL. You can use the editor of your choice to develop the code for the function. Once you have written the code, you can load the file with psql . The syntax for loading the file via psql is below.

psql -f filename.sql database

You can login into psql or other client application and execture a query with the CREATE FUNCTION command. This is an example of creating a function using the CREATE FUNCTION command:

Example 9-1. Skeletal PL/pgSQL function


   CREATE FUNCTION first() RETURNS integer AS '

   /*This is the body of a function.
    A block with some calculations would go here*/

' LANGUAGE 'plpgsql';
You can also use the \e option from psql and input your function into the edit buffer.

Finnally, you can use pgaccess to create a PL/pgSQL function. PgAccess is another client application that we cover in this book. If you have not yet reviewed the PgAccess chapter you may want to do so now.

For more information about creating a function, please refer to Chapter 4 . The subsequent sections are aimed at helping you understand how to develop functions using the PL/pgSQL procedural language.