Re: libpq: How to cancel a COPY ... TO statement?

From: Tom Lane <tgl(at)sss(dot)pgh(dot)pa(dot)us>
To: Daniel Frey <d(dot)frey(at)gmx(dot)de>
Cc: pgsql-general(at)lists(dot)postgresql(dot)org
Subject: Re: libpq: How to cancel a COPY ... TO statement?
Date: 2021-11-08 19:05:41
Message-ID: 991131.1636398341@sss.pgh.pa.us
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-general

Daniel Frey <d(dot)frey(at)gmx(dot)de> writes:
> after sending a COPY ... TO statement with PQsendQuery(), how can I cancel it properly?

> I tried using PQcancel(),

That's the correct way.

> but it seems to have no effect. Calling PQgetCopyData() or PQgetResult() afterwards does not go into a failure state. And I don't want to call PQgetCopyData() until it returns -1, as this might be a lot of data being read from the server that I don't need.

You can't expect instantaneous response to a cancel. For one thing, the
server might have already stuffed a good deal of data down the pipe.
You should keep pulling (and discarding) data until you get the end
or error response.

regards, tom lane

In response to

Browse pgsql-general by date

  From Date Subject
Next Message Christophe Pettus 2021-11-08 19:13:25 Re: Question: Is it possible to get the new xlog position after query execution?
Previous Message Daniel Frey 2021-11-08 18:59:01 libpq: How to cancel a COPY ... TO statement?