Database Reference
In-Depth Information
hannu=# CREATE FUNCTION add(int, int)
hannu-# RETURNS int
hannu-# AS '/usr/pgsql-9.2/lib/add_func',
'add_ab'
hannu-# LANGUAGE C STRICT;
CREATE FUNCTION
And voila—you have created your first PostgreSQL C-language extension function:
hannu=# select add(1,2);
add
-----
3
(1 row)
add_func.sql.in
While what we just covered is all that is needed to have a C function in your data-
base, it is often more convenient to put the preceding CREATE FUNCTION statement
in an SQL file.
You usually do not know the final path of where PostgreSQL is installed when writing
the code, especially in the light of running on multiple versions of PostgreSQL and/
or on multiple operation systems. Here also PGXS can help.
You need to write a file called add_funcs.sql.in as follows:
CREATE FUNCTION add(int, int) RETURNS int
AS 'MODULE_PATHNAME', 'add_ab'
LANGUAGE C STRICT;
And then add the following line in your Makefile function right after the MODULES=
line:
DATA_built = add_func.sql
Search WWH ::




Custom Search