I am trying to iterate through a table to check if a row of data has already been committed. I inserted 5 rows then worked out the solution to check if working row exists before inserting or skipping. This worked for 10 rows of data. I then took out the limitation and tried to insert all of the remaining rows. However, at row 18 my solution hits a wall giving me the error:
Traceback (most recent call last):
...
cursor_object.execute("""SELECT COUNT(*)
pyodbc.DataError: ('22003', '[22003] [Microsoft][ODBC Driver 17 for SQL Server][SQL Server]Arithmetic overflow error converting nvarchar to data type numeric. (8115) (SQLExecDirectW)')
This is the code that I adapted from this discussion on Stack Overflow.
for filing in directory_list:
value_list = []
value = filing['filing']['report_num']
print(filing)
cursor_object.execute("""SELECT COUNT(*)
FROM filings_table
WHERE report_num = {}
GROUP BY report_num""".format(value))
exists = cursor_object.fetchone()
print(exists)
It fails on the last filing shown. The one immediately above it is a numeric anomaly in the numbering sequence. I have verified that it is valid in the source index.json file.
Filing already in database.
{'filing': {'report_num': '999999999520001257', 'filing_date': '2020-05-27', 'url': 'https://www.sec.gov/Archives/edgar/data//0001465885/999999999520001257/9999999995-20-001257-index.html', 'report_type': 'Form EFFECT', 'cik_num': '0001465885'}}
(1, )
Filing already in database.
{'filing': {'report_num': '000162828020008319', 'filing_date': '2020-05-22', 'url': 'https://www.sec.gov/Archives/edgar/data//0001465885/000162828020008319/0001628280-20-008319-index.html', 'report_type': 'Form CORRESP', 'cik_num': '0001465885'}}
Traceback (most recent call last):
How can I resolve this issue where there shouldn't be any arithmetic or conversion happening?
Edit: The select function returns 'None' if there is no match and '(1, )' if there is a match.