Created
March 24, 2017 08:06
-
-
Save mydreambei-ai/63a22e87a8182bdbdc1fd2d6ea8d9f83 to your computer and use it in GitHub Desktop.
postgresql dynamic loading c functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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