Skip to content

Commit aa6fee8

Browse files
committed
inserttable: update documentation
1 parent fe08ff2 commit aa6fee8

2 files changed

Lines changed: 6 additions & 10 deletions

File tree

docs/contents/pg/connection.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -495,7 +495,8 @@ This method allows to *quickly* insert large blocks of data in a table.
495495
Internally, it uses the COPY command of the PostgreSQL database.
496496
The method takes an iterable of row values which must be tuples or lists
497497
of the same size, containing the values for each inserted row.
498-
These may contain string, integer, long or double (real) values.
498+
These may contain string, integer, long or double (real) values as well as
499+
date, time, datetime or timedelta objects.
499500
``columns`` is an optional tuple or list of column names to be passed on
500501
to the COPY command.
501502
The number of rows affected is returned.

ext/pgconn.c

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -792,6 +792,7 @@ conn_inserttable(connObject *self, PyObject *args, PyObject *kwds)
792792

793793
encoding = PQclientEncoding(self->cnx);
794794

795+
/* import datetime C API (this is not compatible with subinterpreters) */
795796
PyDateTime_IMPORT;
796797
if (PyErr_Occurred()) {
797798
return NULL; /* pass the error */
@@ -993,15 +994,9 @@ conn_inserttable(connObject *self, PyObject *args, PyObject *kwds)
993994
Py_DECREF(s);
994995
}
995996
}
996-
else if (PyLong_Check(item)) {
997-
PyObject *s = PyObject_Str(item);
998-
const char *t = PyUnicode_AsUTF8(s);
999-
1000-
ext_char_buffer_s(&buffer, t);
1001-
Py_DECREF(s);
1002-
}
1003-
else if (PyDate_Check(item) || PyDateTime_Check(item) ||
1004-
PyTime_Check(item) || PyDelta_Check(item)) {
997+
else if (PyLong_Check(item) || PyDate_Check(item) ||
998+
PyDateTime_Check(item) || PyTime_Check(item) ||
999+
PyDelta_Check(item)) {
10051000
PyObject *s = PyObject_Str(item);
10061001
const char *t = PyUnicode_AsUTF8(s);
10071002

0 commit comments

Comments
 (0)