My table has 24 columns around half of the column in my table are of float datatype. Specified 24 filed, I have truncated the insert statement here.
csv_data = csv.reader(file('filename.csv'))
for row in csv_data:
cursor.execute('insert into ddreplication (CTX, Mode,...,Max_repl_streams) values (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)', tuple(row))
Error:
File "pymssql.pyx", line 467, in pymssql.Cursor.execute
(pymssql.c:7561)
pymssql.OperationalError: (8114, 'Error converting data type varchar to float.DB-Lib error message 20018, severity 16:\nGeneral SQL
Server error: Check messages from the SQL Server\n')
Im having almost the same code on another script which is running fine without any issues.
Output of "SELECT COLUMN_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='ddreplication' ORDER BY ORDINAL_POSITION"
[(u'CTX', u'int'), (u'Mode', u'nvarchar'), (u'Destination', u'nvarchar'), (u'Connection_Host', u'nvarchar'), (u'Enabled', u'nvarchar'), (u'Low_bandwidth_optimization', u'nvarchar'), (u'Replication_encryption', u'nvarchar'), (u'Replication_propagate_retention_lock', u'nvarchar'), (u'Local_fs_status', u'nvarchar'), (u'Connection', u'nvarchar'), (u'State', u'nvarchar'), (u'Error', u'nvarchar'), (u'Network_bytes_to_destination', u'float'), (u'PreComp_bytes_written_to_source', u'float'), (u'PreComp_bytes_sent_to_destination', u'float'), (u'Bytes_after_synthetic_optimization', u'float'), (u'Bytes_after_filtering_by_destination', u'float'), (u'Bytes_after_low_bandwidth_optimization', u'float'), (u'Bytes_after_local_comp', u'float'), (u'PreComp_bytes_remaining', u'float'), (u'Compression_ration', u'float'), (u'Synced_as_of_time', u'nvarchar'), (u'Current_throttle', u'nvarchar'), (u'Max_repl_streams', u'nvarchar')]
cursor.execute("SELECT COLUMN_NAME, DATA_TYPE FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='ddreplication' ORDER BY ORDINAL_POSITION"); print(cursor.fetchall())
– Gord Thompsoncursor.execute
line: [print(i, is_float(v)) for i,v in enumerate(row)] – Arminius