Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

5
  • 21
    Using psycopg2's cursor.copy_from the file is handled by the client. It doesn't even need to be a file system file: any python file-like object works fine. Check initd.org/psycopg/docs/cursor.html#cursor.copy_from Commented Feb 16, 2010 at 10:24
  • 1
    In that case it would be interesting to see how it's actually inserted into the database - I was under the impression PostgreSQL's COPY only read from the server's local file system and there was no way to bulk copy a file across using the client. Commented Feb 16, 2010 at 10:28
  • 5
    It can also read from STDIN, which mean data come from the client application. See copy command docs: postgresql.org/docs/8.4/static/sql-copy.html Commented Feb 16, 2010 at 13:59
  • 2
    Using copy server-side is hard to beat for speed. Commented Feb 16, 2010 at 14:21
  • 1
    As detailed in this great comparison by Haki Benita, the main drawback of using copy is the lack of extensive support for complex data types (a better option is using pyscopg's execute_batch/execute_values if you have such a requirement...) Commented Dec 18, 2020 at 15:22