Database Reference
In-Depth Information
CREATE EXTENSION chap8_add;
But it is relatively more complex to set up, so we are not explaining it here. We
have a full chapter dedicated to Extensions later in this topic.
Summary for writing a C function
Writing a C function used in PostgreSQL is a straightforward process.
1. Write the C code in
modulename.c
.
2. Write the SQL code for
CREATE FUNCTION
in
modulename.sql.in
.
3. Write a
Makefile
function.
4. Run
make
to compile a C file and generate
modulename.sql
.
5. Run
sudo make install
to install the generated files.
6. Run the generated
modulename.sql
in your target
databasehannu#
\i /<path>/modulename.sql
.
Note that you must run the SQL code in any database you want to use your function.
If you want all your new databases to have access to your newly generated function,
add the function to your template database by running the
modulename.sql
file in
database
template1
or any other database you are explicitly specifying in
CREATE
DATABASE
command.