writeToCopy
Writes a chunk of data to the server.
Each call is one protocol message and one flush, so chunks want to be substantial rather than row-sized.
Before the chunk goes out, whatever the server has sent since the last one is read. During a COPY IN it sends nothing unless it is ending the copy, so this costs one look at the socket. A server that rejected a row has already left copy mode and drops any data that still arrives, so the rejection is raised here instead of the chunk being sent, and the operation is finished. A server that ended the session is caught the same way, while its FATAL can still be read: written first, the chunk would draw a reset, and a Windows client discards what it had not read when one arrives. That holds where the server closes the connection gracefully. A stock PostgreSQL on Windows resets it by itself as the backend exits, and the FATAL goes with it unless a chunk was about to go out in between.
Parameters
Throws
RESOURCE_CLOSED if the operation has already finished.
if the server rejected a row it could not parse.
if the server rejected a row that breaks a constraint.
if the server ended the session.