4

I am using Python to_sql function to insert data in a database table from Pandas dataframe.

I am able to insert data in database table but I want to know in my code how many records are inserted . How to know record count of inserts ( i do not want to write one more query to access database table to get record count)?

Also, is there a way to see logs for this function execution. like what were the queries executed etc.

PythonDeveloper
  • 289
  • 1
  • 4
  • 24

1 Answers1

0

There is no way to do this, since python cannot know how many of the records being inserted were already in the table.

Igor Rivin
  • 4,632
  • 2
  • 23
  • 35
  • why does it have to know that ? I am using a simple insert, and looking for something similar to SQL%Rowcount function in oracle where I get how many rows were affected by my query. – PythonDeveloper May 16 '20 at 21:26
  • @Ummed because if you are inserting 17 rows, and 12 were already in the table, it only inserted 5. Any function with a % in Oracle is (obviously) not standard SQL. – Igor Rivin May 16 '20 at 21:31
  • if I add if_exists='append', it will insert all records irrespective of 'if a similar record exists in database table or not'. – PythonDeveloper May 16 '20 at 21:36
  • @Ummed That makes no sense. You cannot duplicate primary keys, for example. – Igor Rivin May 16 '20 at 21:38