@@ -220,11 +220,28 @@ def query_factory() -> Query:
220
220
columns_to_types_create = columns_to_types .copy ()
221
221
self ._convert_df_datetime (df , columns_to_types_create )
222
222
self .create_table (temp_table , columns_to_types_create )
223
- rows : t .List [t .Tuple [t .Any , ...]] = list (
224
- df .replace ({np .nan : None }).itertuples (index = False , name = None ) # type: ignore
225
- )
226
223
conn = self ._connection_pool .get ()
227
- conn .bulk_copy (temp_table .sql (dialect = self .dialect ), rows )
224
+
225
+ if self ._connection_pool .driver == "pyodbc" :
226
+ cursor = conn .cursor ()
227
+
228
+ # Prepare the insert query
229
+ column_names = ', ' .join ([col for col in columns_to_types .keys ()])
230
+ placeholders = ', ' .join (['?' for _ in columns_to_types .keys ()])
231
+ insert_query = f"INSERT INTO { temp_table .sql (dialect = self .dialect )} ({ column_names } ) VALUES ({ placeholders } )"
232
+
233
+ # Replace NaN with None and prepare rows
234
+ rows = [tuple (row ) for row in df .replace ({np .nan : None }).itertuples (index = False , name = None )]
235
+
236
+ # Execute the query with multiple rows
237
+ cursor .executemany (insert_query , rows )
238
+ conn .commit ()
239
+ cursor .close ()
240
+ else : # Use bulk_copy for pymssql
241
+ rows : t .List [t .Tuple [t .Any , ...]] = list (
242
+ df .replace ({np .nan : None }).itertuples (index = False , name = None ) # type: ignore
243
+ )
244
+ conn .bulk_copy (temp_table .sql (dialect = self .dialect ), rows )
228
245
return exp .select (* self ._casted_columns (columns_to_types )).from_ (temp_table ) # type: ignore
229
246
230
247
return [
0 commit comments