Can anyone point me to examples for using libpq's asynchronous command processing?
My client C program needs to perform a bulk load. I've written code to do this by both:
1. Dumping data to file and loading it into a table using "COPY table_name FROM 'file_name'", and
2. Writing directly into PG using "COPY table_name FROM STDIN" and then making buffered calls to PQputCopyData.
Using binary communication, I'm feeling pretty smug about my bulkload times, but they're still of the order of a
minute.However, my program must be able to do other things during this period. So I'm investigating the possibility of
rejigging(1) so that I:
a. Dump binary data into a file,
b. Instruct PG to copy this data into a table asynchronously,
c. Go away and do other exciting things,
d. Upon completion of the load, a callback of mine is triggered.
I have this (kind of) implemented by forking a child process that sends the "COPY table_name FROM 'file_name'" command
sothe main process can keep on trucking, but I'm not happy with it.
Is this the kind of thing that I should be able to achieve more elegantly using libpq's asynchronous functions
(PQsendQuery,PQgetResult etc)? Can anyone give me a clue how to arrange the function calls?
Many thanks,
Nathaniel