AGE Contribution Guide

ahmedmohamed

Ahmed Mohamed

Posted on June 28, 2023

AGE Contribution Guide

In the previous blog we wrote add_two_numbers function implementation.

file name is add_numbers.c

#include "postgres.h"
#include <string.h>
#include "fmgr.h"

PG_MODULE_MAGIC;

PG_FUNCTION_INFO_V1(add_one);

Datum
add_two_numbers(PG_FUNCTION_ARGS)
{
    int32   arg1 = PG_GETARG_INT32(0);
    int32   arg2 = PG_GETARG_INT32(1);

    PG_RETURN_INT32(arg1 + arg2);
}

Enter fullscreen mode Exit fullscreen mode

Now, let's add this function to age.
save the file in the following path: src/backend/commands

then add the next line to makefile on the top directory of the project
src/backend/commands/add_numbers.o
add this line in OBJS section.

Add the signature to the age--1.3.0.sql at the end of the file


CREATE FUNCTION ag_catalog.add_numbers()
RETURNS Integer
LANGUAGE c
AS 'MODULE_PATHNAME';
Enter fullscreen mode Exit fullscreen mode

then run the following commands in the project directory

sudo make clean PG_CONFIG=/usr/local/pgsql/bin/pg_config
sudo make PG_CONFIG=/usr/local/pgsql/bin/pg_config
sudo make install PG_CONFIG=/usr/local/pgsql/bin/pg_config
Enter fullscreen mode Exit fullscreen mode

Now we are done, after running the postgres server you can use this function as follows

select * from ag_catalog.add_numbers(2,3);
Enter fullscreen mode Exit fullscreen mode

apache age github repo
Create a Custom Function in Postgres

💖 💪 🙅 🚩
ahmedmohamed
Ahmed Mohamed

Posted on June 28, 2023

Join Our Newsletter. No Spam, Only the good stuff.

Sign up to receive the latest update from our blog.

Related