Skip to content

Commit 5a53f03

Browse files
Roger Thomasjreback
Roger Thomas
authored andcommitted
PERF: Only do case sensitive check when not lower case
closes #12876 Author: Roger Thomas <[email protected]> Closes #12880 from RogerThomas/to_sql_only_check_case_when_not_lower and squashes the following commits: fda61d4 [Roger Thomas] Update docs abbaf4b [Roger Thomas] Only do case sensitive check when not lower case
1 parent 77be872 commit 5a53f03

File tree

2 files changed

+18
-13
lines changed

2 files changed

+18
-13
lines changed

doc/source/whatsnew/v0.18.1.txt

+1
Original file line numberDiff line numberDiff line change
@@ -203,6 +203,7 @@ Performance Improvements
203203

204204

205205

206+
- Improved performance of ``DataFrame.to_sql`` when checking case sensitivity for tables. Now only checks if table has been created correctly when table name is not lower case. (:issue:`12876`)
206207

207208

208209

pandas/io/sql.py

+17-13
Original file line numberDiff line numberDiff line change
@@ -1248,19 +1248,23 @@ def to_sql(self, frame, name, if_exists='fail', index=True,
12481248
schema=schema, dtype=dtype)
12491249
table.create()
12501250
table.insert(chunksize)
1251-
# check for potentially case sensitivity issues (GH7815)
1252-
engine = self.connectable.engine
1253-
with self.connectable.connect() as conn:
1254-
table_names = engine.table_names(
1255-
schema=schema or self.meta.schema,
1256-
connection=conn,
1257-
)
1258-
if name not in table_names:
1259-
warnings.warn("The provided table name '{0}' is not found exactly "
1260-
"as such in the database after writing the table, "
1261-
"possibly due to case sensitivity issues. Consider "
1262-
"using lower case table names.".format(name),
1263-
UserWarning)
1251+
if (not name.isdigit() and not name.islower()):
1252+
# check for potentially case sensitivity issues (GH7815)
1253+
# Only check when name is not a number and name is not lower case
1254+
engine = self.connectable.engine
1255+
with self.connectable.connect() as conn:
1256+
table_names = engine.table_names(
1257+
schema=schema or self.meta.schema,
1258+
connection=conn,
1259+
)
1260+
if name not in table_names:
1261+
msg = (
1262+
"The provided table name '{0}' is not found exactly as "
1263+
"such in the database after writing the table, possibly "
1264+
"due to case sensitivity issues. Consider using lower "
1265+
"case table names."
1266+
).format(name)
1267+
warnings.warn(msg, UserWarning)
12641268

12651269
@property
12661270
def tables(self):

0 commit comments

Comments
 (0)