@@ -1474,35 +1474,6 @@ def columns(self, table=None, catalog=None, schema=None, column=None):
14741474 # Use the helper method to prepare the result set
14751475 return self ._prepare_metadata_result_set (fallback_description = fallback_description )
14761476
1477- @staticmethod
1478- def _select_best_sample_value (column ):
1479- """
1480- Selects the most representative non-null value from a column for type inference.
1481-
1482- This is used during executemany() to infer SQL/C types based on actual data,
1483- preferring a non-null value that is not the first row to avoid bias from placeholder defaults.
1484-
1485- Args:
1486- column: List of values in the column.
1487- """
1488- non_nulls = [v for v in column if v is not None ]
1489- if not non_nulls :
1490- return None
1491- if all (isinstance (v , int ) for v in non_nulls ):
1492- # Pick the value with the widest range (min/max)
1493- return max (non_nulls , key = lambda v : abs (v ))
1494- if all (isinstance (v , float ) for v in non_nulls ):
1495- return 0.0
1496- if all (isinstance (v , decimal .Decimal ) for v in non_nulls ):
1497- return max (non_nulls , key = lambda d : len (d .as_tuple ().digits ))
1498- if all (isinstance (v , str ) for v in non_nulls ):
1499- return max (non_nulls , key = lambda s : len (str (s )))
1500- if all (isinstance (v , datetime .datetime ) for v in non_nulls ):
1501- return datetime .datetime .now ()
1502- if all (isinstance (v , datetime .date ) for v in non_nulls ):
1503- return datetime .date .today ()
1504- return non_nulls [0 ] # fallback
1505-
15061477 def _transpose_rowwise_to_columnwise (self , seq_of_parameters : list ) -> tuple [list , int ]:
15071478 """
15081479 Convert sequence of rows (row-wise) into list of columns (column-wise),
@@ -1675,11 +1646,7 @@ def executemany(self, operation: str, seq_of_parameters: list) -> None:
16751646 else :
16761647 # Use auto-detection for columns without explicit types
16771648 column = [row [col_index ] for row in seq_of_parameters ] if hasattr (seq_of_parameters , '__getitem__' ) else []
1678- if not column :
1679- # For generators, use the sample row for inference
1680- sample_value = sample_row [col_index ]
1681- else :
1682- sample_value = self ._select_best_sample_value (column )
1649+ sample_value , min_val , max_val = self ._compute_column_type (column )
16831650
16841651 dummy_row = list (sample_row )
16851652 paraminfo = self ._create_parameter_types_list (
0 commit comments