Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Can't compile C program as PostgreSQL stored procedure

Tags:

c

postgresql

everyone. I try to make simple example of how to create stored procedures in PostgreSQL written in C language. When compiling "test.c" there's an error "Unknown type Datum". I use Version 1 Calling convention. PostgreSQL 9.1 is installed on my server under Ubuntu 11.10. Please help. By the way does anybody have step-by-step example of creating stored procedures in C language? Thanks

like image 842
geaden Avatar asked May 13 '26 03:05

geaden


2 Answers

I wrote up a mind dump while I was doing this awhile back on FreeBSD. Here is the link in case it might help.

Compile C function to stored procedure brain dump

like image 85
Kuberchaun Avatar answered May 14 '26 18:05

Kuberchaun


  1. Search for the postgres server includes path (Debian Wheezy = /usr/include/postgresql/9.1/server/)
  2. Change #include directives inside the PostgreSQL example (foo.c) from #include "" to #include<>
  3. To compile, add the include search path with the directive

    -I (gcc -fpic -c foo.c -I/usr/include/postgresql/9.1/server/)

  4. Continue as its said in the Postgres documentation

http://www.postgresql.org/docs/9.1/static/xfunc-c.html

like image 38
Rafael Gandía Avatar answered May 14 '26 16:05

Rafael Gandía



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!