COPY is not supported. Attempting it puts the connection in
unrecoverable state, with pipeline sync failing and pipeline exit
complaining that there are still results. So let's try to not get in
that state.
def _start_copy_gen(self, statement: Query) -> PQGen[None]:
"""Generator implementing sending a command for `Cursor.copy()."""
+
+ # The connection gets in an unrecoverable state if we attempt COPY in
+ # pipeline mode. Forbid it explicitly.
+ if self._conn._pipeline:
+ raise e.NotSupportedError("COPY cannot be used in pipeline mode")
+
yield from self._start_query()
query = self._convert_query(statement)
assert cm.value.sqlstate == "42601"
+def test_copy(conn):
+ with conn.pipeline():
+ cur = conn.cursor()
+ with pytest.raises(e.NotSupportedError):
+ with cur.copy("copy (select 1) to stdout"):
+ pass
+
+
def test_pipeline_processed_at_exit(conn):
with conn.cursor() as cur:
with conn.pipeline() as p:
assert cm.value.sqlstate == "42601"
+async def test_copy(aconn):
+ async with aconn.pipeline():
+ cur = aconn.cursor()
+ with pytest.raises(e.NotSupportedError):
+ async with cur.copy("copy (select 1) to stdout") as copy:
+ await copy.read()
+
+
async def test_pipeline_processed_at_exit(aconn):
async with aconn.cursor() as cur:
async with aconn.pipeline() as p: