Now that you have created a dynamically linkable object file, you
must register its functions with POSTGRESQL. The CREATE
FUNCTION command registers a new function by storing
information in the database. Figure shows
the CREATE FUNCTION command for ctof.
test=> CREATE FUNCTION ctof(float)
test-> RETURNS float
test-> AS '/users/pgman/sample/ctof.so'
test-> LANGUAGE 'C';
CREATE
The function ctof takes a float argument and returns a float. The SQL data type float is the same as the C type double used in ctof(). The dynamically linkable object file is specified as /users/pgman/sample/ctof.so and is written in the C language.
A single object file can contain many functions. You must use CREATE
FUNCTION to register each function you want to access from POSTGRESQL.
CREATE FUNCTION also allows nonobject files to be
used as functions (see Chapter ).
Once the functions are registered, they can be called just like POSTGRESQL
internal functions. Figure shows the
ctof() function used in a SELECT statement.
test=> SELECT ctof(20);
ctof
------
68
(1 row)
See CREATE_FUNCTION for more information.