I'm sending various data frames to Microsoft SQL Server using the Pandas function to_sql()
and a mssql+pyodbc://
connection made with sqlalchemy.create_engine
. Sometimes to_sql()
returns the number of rows written, which is what I expect from the documentation on Returns:
Number of rows affected by to_sql. None is returned if the callable passed into method does not return an integer number of rows.
The number of returned rows affected is the sum of the rowcount attribute of sqlite3.Cursor or SQLAlchemy connectable which may not reflect the exact number of written rows as stipulated in the sqlite3 or SQLAlchemy.
But in some cases I'm seeing it return negative values like -1, 2, -11, -56. If I use method="multi"
this behavior goes away. Here I'm writing a table with 325 records:
>>> PLSUBMITTALTYPE.to_sql("PLSubmittalType", con=data_lake, if_exists="replace")
-1
>>> PLSUBMITTALTYPE.to_sql("PLSubmittalType", con=data_lake, if_exists="replace", method="multi", chunksize = 50)
325
What do those negative values mean? It appears to be succeeding in writing to the database in those cases.