I'm working from and example in the psycopg3 documentation to copy a table from one database to another: link
dsn_src = 'postgresql:///dev_db'
dsn_tgt = 'postgresql:///prod_test'
with psycopg.connect(dsn_src) as conn1, psycopg.connect(dsn_tgt) as conn2:
with conn1.cursor().copy("COPY sample TO STDOUT (FORMAT BINARY)") as copy1:
with conn2.cursor().copy("COPY sample FROM STDIN (FORMAT BINARY)") as copy2:
for data in copy1:
copy2.write(data)
running this results in the following error
QueryCanceled: COPY from stdin failed: error from Python: TypeError - can't write memoryview
CONTEXT: COPY sample, line 1
The source and target schema are identical, as the documentation recommends, and this error persists if the format specification (FORMAT BINARY)
is removed.
Is there are way to resolve this memoryview
error?