Open utterances-bot opened 1 year ago
HI Daniele, thank you very much for laying out the updates to psycopg3 (or just psycopg, as you say).
In the example around block-level copy, IDLE complains that a colon is missing after while data := copy.read() but doing so results in an error when using the overall example.
After substituting my_tablename for mytable in the portion that reads COPY mytable TO STDOUTand using the rest of your code, the following error appears for the f.write(data) section:
write() argument must be str, not memoryview
Is the syntax different in newer versions of psycopg? I'm using 3.1.4
The file should be open in binary mode, using open(FILENAME, "wb")
. I will fix the article. Thank you for the report!
You're welcome; I see the "wb" has been updated. IDLE is still asking for a colon after copy.read() before it will execute, but perhaps that's just my version of Python (3.11)
i am getting a 'Cursor' object has no attribute 'copy_expert' error.
The new COPY support in psycopg3 — Psycopg
Python adapter for PostgreSQL
https://www.psycopg.org/articles/2020/11/15/psycopg3-copy/