executemany()
expects a sequence of rows; the entries in the list must themselves be sequences of parameters, even when the inserted rows consist of just one value each:
sql_fill_table_build = [('1',), ('2',), ('3',), ('4',), ('55',)]
or use lists:
sql_fill_table_build = [['1'], ['2'], ['3'], ['4'], ['55']]
The reason it works with just the flat list of strings minus the '55'
entry is because strings are sequences too, but '55'
is a sequence of length two. Thus, the last entry tries to insert two parameters, '5'
and '5'
, but your query only expects one parameter.
If some API gives you just a flat list, you can convert the flat list to a nested sequence with a list comprehension on insertion:
DB_GATEWAY.executemany(sql_fill_table_build, [(v,) for v in sql_fill_table_header])
I haven't tested this with cx_Oracle
, but some database adapters also accept an iterable, so a generator expression might be more efficient:
DB_GATEWAY.executemany(sql_fill_table_build, ((v,) for v in sql_fill_table_header))
but it could be that cx_Oracle
demands a sequence.