Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

articles/2020/11/15/psycopg3-copy/ #20

Open
utterances-bot opened this issue Dec 7, 2022 · 4 comments
Open

articles/2020/11/15/psycopg3-copy/ #20

utterances-bot opened this issue Dec 7, 2022 · 4 comments

Comments

@utterances-bot
Copy link

The new COPY support in psycopg3 — Psycopg

Python adapter for PostgreSQL

https://www.psycopg.org/articles/2020/11/15/psycopg3-copy/

Copy link

ts1g commented Dec 7, 2022

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

@dvarrazzo
Copy link
Member

The file should be open in binary mode, using open(FILENAME, "wb"). I will fix the article. Thank you for the report!

Copy link

ts1g commented Dec 8, 2022

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)

Copy link

i am getting a 'Cursor' object has no attribute 'copy_expert' error.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants