Обсуждение: copy_from and rowcount
I'm wondering if it's possible to get the number of rows copied when using copy_from? I would've thought the .rowcount attribute of the cursor would have this value, but that doesn't seem to be the case. -Ryan Kelly
On 12/09/2013 18:06, Ryan Kelly wrote: > I'm wondering if it's possible to get the number of rows copied when > using copy_from? I would've thought the .rowcount attribute of the cursor > would have this value, but that doesn't seem to be the case. Sorry for the late asnwer. If I remember correctly the libpq docs don't say if it is possible to retrieve the number of inserted columns and we're not sending data line-by-line but as chunks so counting the lines isn't possible. Maybe (a big maybe) the final PGresult contains that but I can't find this documented anywhere. We'll need to instrument psycopg to print PGresult fields and do a bit of guesswork. federico -- Federico Di Gregorio federico.digregorio@dndg.it Di Nunzio & Di Gregorio srl http://dndg.it Those who do not study Lisp are doomed to reimplement it. Poorly. -- from Karl M. Hegbloom .signature
On Fri, Sep 20, 2013 at 10:04 AM, Federico Di Gregorio <fog@dndg.it> wrote:
--
Thanks,
David Blewett
On 12/09/2013 18:06, Ryan Kelly wrote:Sorry for the late asnwer.
> I'm wondering if it's possible to get the number of rows copied when
> using copy_from? I would've thought the .rowcount attribute of the cursor
> would have this value, but that doesn't seem to be the case.
If I remember correctly the libpq docs don't say if it is possible to
retrieve the number of inserted columns and we're not sending data
line-by-line but as chunks so counting the lines isn't possible. Maybe
(a big maybe) the final PGresult contains that but I can't find this
documented anywhere. We'll need to instrument psycopg to print PGresult
fields and do a bit of guesswork.
"This function returns a string containing the number of rows affected by the SQL statement that generated the PGresult. This function can only be used following the execution of a SELECT, CREATE TABLE AS, INSERT, UPDATE, DELETE, MOVE, FETCH, or COPY statement, or an EXECUTE of a prepared query that contains an INSERT, UPDATE, or DELETE statement. If the command that generated the PGresult was anything else,
You can use the
PQcmdTuples
[1] function on the PGresult returned by the copy operation:"This function returns a string containing the number of rows affected by the SQL statement that generated the PGresult. This function can only be used following the execution of a SELECT, CREATE TABLE AS, INSERT, UPDATE, DELETE, MOVE, FETCH, or COPY statement, or an EXECUTE of a prepared query that contains an INSERT, UPDATE, or DELETE statement. If the command that generated the PGresult was anything else,
PQcmdTuples
returns an empty string. The caller should not free the return value directly. It will be freed when the associated PGresult handle is passed to PQclear
."--
Thanks,
David Blewett