[Libpqxx-general] "Posting" a call to a pl/pgSQL function using libpqxx
Jeroen T. Vermeulen
jtv at xs4all.nl
Thu Jun 5 20:18:05 UTC 2008
On Thu, June 5, 2008 17:24, Peter Geoghegan wrote:
> Hello,
Hi Peter!
> I am writing an application that requires that I call a pl/pgSQL
> function, which performs a potentially lengthy operation. That
> function returns void. I am not interested in the result of that
> function, and it should never throw an exception.
>
> I'd like to avoid having to wait for that function to return - in
> effect, I'd like to "post" a call to the function, because not doing
> so could cause my application to stall for an annoyingly long time.
> I've thought of creating a pqxx "back burner" thread, but this would
> necessitate adopting all of my existing code to it, and in any case,
> the simplest solution is preferable. I hope the back burner thread
> doesn't turn out to be the simplest solution, because, absolutely, it
> isn't all that simple!
This is one of the real reasons why we have the pipeline: it lets you hide
latency by separating the issuing of the query from waiting for the
result, but without too much added complication.
Basically you just feed your query in one end of the pipeline, and when
you absolutely have to move on with the next query, you collect the
result, close the pipeline, and proceed as normal. Or if you have lots of
queries that you don't immediately need the results to, you just keep
using the pipeline as a kind of "asynchronous transaction."
See include/pqxx/pipeline.hxx!
Jeroen
More information about the Libpqxx-general
mailing list