Is it safe to use the extended protocol with COPY?

Started by Daniele Varrazzoover 4 years ago3 messages
#1Daniele Varrazzo
daniele.varrazzo@gmail.com

Hello,

in psycopg 3 we are currently using PQexecParams - although with no
params - to send COPY commands. The reason is mostly to avoid people
to send COPY together with other statements. Especially if other
operations are chained after COPY: we would only notice them after
copy is finished. Data changes might have been applied by then, so
throwing an exception seems impolite (the result might have been
applied already) but managing the result is awkward too.

Someone [1]https://github.com/psycopg/psycopg/issues/78 has pointed out this conversation [2]/messages/by-id/CAMsr+YGvp2wRx9pPSxaKFdaObxX8DzWse+OkWk2xpXSvT0rq-g@mail.gmail.com which suggests that
COPY with extended protocol might break in the future.

[1]: https://github.com/psycopg/psycopg/issues/78
[2]: /messages/by-id/CAMsr+YGvp2wRx9pPSxaKFdaObxX8DzWse+OkWk2xpXSvT0rq-g@mail.gmail.com

As far as PostgreSQL is concerned, would it be better to stick to
PQexec with COPY, and if people append statements afterwards they
would be the ones to deal with the consequences? (being the server
applying the changes, the client throwing an exception)

Thank you very much

-- Daniele

#2Tom Lane
tgl@sss.pgh.pa.us
In reply to: Daniele Varrazzo (#1)
Re: Is it safe to use the extended protocol with COPY?

Daniele Varrazzo <daniele.varrazzo@gmail.com> writes:

Someone [1] has pointed out this conversation [2] which suggests that
COPY with extended protocol might break in the future.

As was pointed out in that same thread, the odds of us actually
breaking that case are nil. I wouldn't recommend changing your
code on this basis.

regards, tom lane

#3Robert Haas
robertmhaas@gmail.com
In reply to: Tom Lane (#2)
Re: Is it safe to use the extended protocol with COPY?

On Wed, Sep 1, 2021 at 2:43 PM Tom Lane <tgl@sss.pgh.pa.us> wrote:

Daniele Varrazzo <daniele.varrazzo@gmail.com> writes:

Someone [1] has pointed out this conversation [2] which suggests that
COPY with extended protocol might break in the future.

As was pointed out in that same thread, the odds of us actually
breaking that case are nil. I wouldn't recommend changing your
code on this basis.

I agree that there doesn't seem to be an risk of a wire protocol
change in the near future, but it might still be a good idea to change
any code that does this on the grounds that the current wire protocol
makes reliable error handling impossible - unless you wait to send
Sync until you see how the server responds to the earlier messages.[1]/messages/by-id/CA+Tgmoa4eA+cPXaiGQmEBp9XisVd3ZE9dbvnbZEvx9UcMiw2tg@mail.gmail.com

[1]: /messages/by-id/CA+Tgmoa4eA+cPXaiGQmEBp9XisVd3ZE9dbvnbZEvx9UcMiw2tg@mail.gmail.com

--
Robert Haas
EDB: http://www.enterprisedb.com