Reputation: 962
I am doing bulk inserts using SQLAlchemy in a loop as follows:
for table, batch in pendingInserts:
self.conn.execute(table.insert(), batch)
where batch
is list of dict
and table
is a SQLAlchemy table. First batch of inserts executes successfully but in subsequent iteration with insert on same table fails with the following error:
StatementError: A value is required for bind parameter 'security_exchange', in parameter group 45 (original cause: InvalidRequestError: A value is required for bind parameter 'security_exchange', in parameter group 45) u'INSERT INTO .....
Here security_exchange
is nullable column in the DB (PostgreSQL), so it in not mandatory and is omitted in all entries in the batch. I am confused why it succeed for the first bulk insert but fails for the second insert on same table. Also for the same table, the number of columns supplied always remains same for all dicts in all batches.
Upvotes: 3
Views: 2121
Reputation: 962
Batch insert needs all items to have same set of columns present for all items in the batch. In my case some of the optional columns (with default values) were getting skipped for some of the items in the batch.
Upvotes: 7