Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

copy_from/copy_to documentation (cursor.rst) incorrect

#59

The documentation for the copy_from/copy_to cursor methods is incorrect and misleading. These methods expect a buffer size as the 5th argument (not counting self) and a sequence of column names only as the 6th argument.

I just wasted 3 hours trying to find out why the following wouldn't work:

cursor.copy_from(
    self.io,
    self.table_name,
    self.COLUMN_SEPARATOR,
    self.NULL_LITERAL,
    self.column_names
)

It kept failing with this error:

...
  File "pg_copy.py", line 51, in copy_from
    self.column_names
TypeError: an integer is required

Only when I went to the psycopg2 source code and started learning about PyArg_ParseTupleAndKeywords and other nasty Python internals it began to dawn on me that I was not insane and a "size" argument needed to be passed before the "columns" argument.

I'm now passing the latter as a keyword argument ...

cursor.copy_from(
    self.io,
    self.table_name,
    self.COLUMN_SEPARATOR,
    self.NULL_LITERAL,
    columns = self.column_names
)

... but the documentation should be fixed to save others from this ordeal.

Reported by Julian Mehnle · June 6th, 2011 @ 11:04 PM

State: resolved
Milestone: none
Assigned to: nobody

Activity

  1. Daniele Varrazzo
    Daniele Varrazzo
    • State changed from new to open

    Sorry for the trouble, will review the docs and make them consistent with the arguments order.

    June 7th, 2011 @ 09:13 AM

  2. Daniele Varrazzo