libpq: do I need PQendcopy after PQgetCopyData?

Started by Nathanielover 16 years ago3 messagesgeneral
Jump to latest
#1Nathaniel
naptrel@yahoo.co.uk

I'm working on a client library, written in C, and am using:

COPY sometable TO STDOUT WITH BINARY

followed by calls to 'PQgetCopyData' to retrieve data from the table as a postgres binary stream.

All my DB interaction is synchronous.

I've had things working for some time, but recent enhancements are getting caught-out by a strange thing: even though my calls to 'PQgetCopyData' exhaust the stream (i.e. 'PQgetCopyData' is being called until it returns '-1'), if I then query the transaction status of the same connection with a call to 'PQtransactionStatus', I get a status of 'PQTRANS_ACTIVE'--it seems the server hasn't realised that the copy is over and done with. I was expecting 'PQTRANS_IDLE'.

So, even though the manual states that it's obsolete, do I need to issue a call to 'PQendcopy' to tell the server that the copy is complete?

Please note: my client application needs to work against postgres v7.4 onwards, so I'm currently developing against a v7.4 test database and haven't (yet) checked to see if the same issue arises under more recent versions (it's a pain to do--it requires a whole bunch of other infrastructure to be switched over to later versions too).

Nathaniel

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Nathaniel (#1)
Re: libpq: do I need PQendcopy after PQgetCopyData?

Nathaniel Trellice <naptrel@yahoo.co.uk> writes:

So, even though the manual states that it's obsolete, do I need to issue a call to 'PQendcopy' to tell the server that the copy is complete?

No, but did you do a PQgetResult? See the description of PQgetCopyData.

regards, tom lane

#3Nathaniel
naptrel@yahoo.co.uk
In reply to: Tom Lane (#2)
Re: libpq: do I need PQendcopy after PQgetCopyData?

Tom Lane wrote:
No, but did you do a PQgetResult? See the description of PQgetCopyData.

Oops! Thanks Tom. Even after many re-reads, I missed that final paragraph in the manual, and have wasted ages on this.
Nathaniel