You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Using Panadas 2.2.3, sqlite3.version 2.6.0 and python 3.12.5, I get an error "table ... already exits" when using to_sql() with if_exists='append'. I just try to append some data from a Pandas df to a SQLite DB table. Using if_exists='replace' produces the same result. In order to make sure that the db connection is active and the columns match, I used some simple print statements in a previous try block and the failing to.sql in the try block with the to_sql command. Also a "select statement" from the same table is used before and works. The first block is executed without an exception and the second block throws the message 'table "groupedData" already exists'.
It turned out that the problem was case sensitivity. I named the SQLite db table "GroupedData" and used "groupedData" in Python with Pandas. While SQL table names are usually not case-sensitive and also sqlite3 is not case-sensitive with table names, to_sql() from Pandas shows a case sensitive behaviour with a error message not indicating the problem properly. Using table_grouped='GroupedData', the try block with to_sql() worked for both "append" and "replace".
Expected Behavior
Either giving a more specific error message or changing the behaviour of to_sql() to be also non case-sensitive would be my suggestion.
Installed Versions
INSTALLED VERSIONS
commit : 0691c5c
python : 3.12.5
python-bits : 64
OS : Windows
OS-release : 11
Version : 10.0.22631
machine : AMD64
processor : Intel64 Family 6 Model 170 Stepping 4, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : de_DE.cp1252
Pandas version checks
I have checked that this issue has not already been reported.
I have confirmed this bug exists on the latest version of pandas.
I have confirmed this bug exists on the main branch of pandas.
Reproducible Example
Issue Description
Please also see: https://stackoverflow.com/questions/79019484/
Output of code on local machine:
Using Panadas 2.2.3, sqlite3.version 2.6.0 and python 3.12.5, I get an error "table ... already exits" when using to_sql() with if_exists='append'. I just try to append some data from a Pandas df to a SQLite DB table. Using if_exists='replace' produces the same result. In order to make sure that the db connection is active and the columns match, I used some simple print statements in a previous try block and the failing to.sql in the try block with the to_sql command. Also a "select statement" from the same table is used before and works. The first block is executed without an exception and the second block throws the message 'table "groupedData" already exists'.
It turned out that the problem was case sensitivity. I named the SQLite db table "GroupedData" and used "groupedData" in Python with Pandas. While SQL table names are usually not case-sensitive and also sqlite3 is not case-sensitive with table names, to_sql() from Pandas shows a case sensitive behaviour with a error message not indicating the problem properly. Using table_grouped='GroupedData', the try block with to_sql() worked for both "append" and "replace".
Expected Behavior
Either giving a more specific error message or changing the behaviour of to_sql() to be also non case-sensitive would be my suggestion.
Installed Versions
INSTALLED VERSIONS
commit : 0691c5c
python : 3.12.5
python-bits : 64
OS : Windows
OS-release : 11
Version : 10.0.22631
machine : AMD64
processor : Intel64 Family 6 Model 170 Stepping 4, GenuineIntel
byteorder : little
LC_ALL : None
LANG : None
LOCALE : de_DE.cp1252
pandas : 2.2.3
numpy : 2.1.1
pytz : 2024.2
dateutil : 2.9.0.post0
pip : 24.2
Cython : None
sphinx : None
IPython : 8.27.0
adbc-driver-postgresql: None
adbc-driver-sqlite : None
bs4 : None
blosc : None
bottleneck : None
dataframe-api-compat : None
fastparquet : None
fsspec : None
html5lib : None
hypothesis : None
gcsfs : None
jinja2 : None
lxml.etree : None
matplotlib : 3.9.2
numba : None
numexpr : None
odfpy : None
openpyxl : None
pandas_gbq : None
psycopg2 : None
pymysql : None
pyarrow : None
pyreadstat : None
pytest : None
python-calamine : None
pyxlsb : None
s3fs : None
scipy : 1.14.1
sqlalchemy : None
tables : None
tabulate : None
xarray : None
xlrd : None
xlsxwriter : None
zstandard : None
tzdata : 2024.1
qtpy : None
pyqt5 : None
The text was updated successfully, but these errors were encountered: