Skip to content

Instantly share code, notes, and snippets.

@mydreambei-ai
Created March 24, 2017 08:06
Show Gist options
  • Save mydreambei-ai/63a22e87a8182bdbdc1fd2d6ea8d9f83 to your computer and use it in GitHub Desktop.
Save mydreambei-ai/63a22e87a8182bdbdc1fd2d6ea8d9f83 to your computer and use it in GitHub Desktop.
postgresql dynamic loading c functions
cc -fpic -c func.c -I`pg_config --includedir-server`
cc -shared -o func.so func.o
#mv func.so server dynamic lib directory
mv func.so `pg_config --pkglibdir`
cd `pg_config --pkglibdir`
chown root:root func.so
#include "postgres.h"
#include "fmgr.h"
#ifdef PG_MODULE_MAGIC
PG_MODULE_MAGIC;
#endif
// https://www.postgresql.org/docs/9.5/static/xfunc-c.html
PG_FUNCTION_INFO_V1(add_one);
Datum
add_one(PG_FUNCTION_ARGS)
{
int32 arg = PG_GETARG_INT32(0);
PG_RETURN_INT32(arg + 1);
}
//
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment