Thread: help with integrating liblpq program

help with integrating liblpq program

From
"Marc Zandvliet"
Date:
Hello,

I've written a small program in C that does a series of SELECTs on my database (sort of a recursive search). I can run
theprogram from the command-line without any trouble - however I want to be able to run the function from within psql.
 

My compilation seems to be ok:

bash-2.04$ gcc -I/usr/include/postgresql -c -o event_tree.o event_tree.c
bash-2.04$ gcc -shared -lpq -o event_tree.so event_tree.o
bash-2.04$

In psql I can create the function:
efsbovic=# create function event_tree(char) returns char as '/var/lib/pgsql/temp/event_tree.so' language 'c';
CREATE
efsbovic=# select event_tree('40');
pqReadData() -- backend closed the channel unexpectedly.       This probably means the backend terminated abnormally
  before or while processing the request.
 
The connection to the server was lost. Attempting reset: Failed.
!#

But as you can see it dies horribly.

I think I'm close - can someone help me out? If I want the function to do this do I still use libpq-fe functions within
theC program or is there another way?
 

regards, Marc