This project is archived and is in readonly mode.
copy_from/copy_to documentation (cursor.rst) incorrect
Reported by Julian Mehnle | June 6th, 2011 @ 11:04 PM
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.
Comments and changes to this ticket
-
Daniele Varrazzo June 7th, 2011 @ 09:13 AM
- State changed from new to open
Sorry for the trouble, will review the docs and make them consistent with the arguments order.
-
Daniele Varrazzo June 7th, 2011 @ 10:24 AM
- State changed from open to resolved
Create your profile
Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป
<b>WARNING:</b> the informations in this tracker are archived. Please submit new tickets or comments to <a href="https://github.com/psycopg/psycopg2/issues">the new tracker</a>.
<br/>
Psycopg is the most used PostgreSQL adapter for the Python programming language. At the core it fully implements the Python DB API 2.0 specifications. Several extensions allow access to many of the features offered by PostgreSQL.