3

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

4
  • 1
    post relevant code, which will save the guess-work for everyone. Commented May 21, 2012 at 13:55
  • 1
    Based on the "Unknown type" diagnostic, it sounds like you've forgotten to #include a header file from the PostgreSQL implementation. Unfortunately, I don't know what that file would be. Commented May 21, 2012 at 15:52
  • You should really show the whole compiler error sequence. Copy and paste. Commented May 21, 2012 at 23:43
  • The problem was I use #include "postgres.h" instead of #include "/usr/include/postgresql/postgres.h". Now I can't compile shared object. code cc -shared -o /usr/include/postgresql/foo.so /usr/include/postgresql/foo.o. cc: error: /usr/include/postgresql/foo.o: No such file or directory cc: fatal error: no input files compilation terminated. Thanks Commented May 22, 2012 at 8:05

2 Answers 2

2

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

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you, very much! I'll try as soon as get my pc
1
  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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.