I keep having a strange issue with my program doing SQL inserts. I'm periodically (once a day) sending a lot of data using pymysql in a single INSERT statement and every few days I get the following error:
(sqlalchemy.exc.InvalidRequestError) A value is required for bind parameter 'D' [SQL:
In my code, this is how the db is connected to and insert is done:
Session creation:
engine = sqlalchemy.create_engine(db_host, echo = False)
self.metadata = sqlalchemy.MetaData(engine)
DB_session = sqlalchemy.orm.sessionmaker(bind = engine)
session = DB_session()
Insert function:
def insert(self,sql):
complete = False
try:
self.session.execute(sql)
self.session.commit()
complete = True
except Exception as e:
# Do some logging
finally:
return complete
And here's what a typical insert statement would look like:
INSERT INTO my_db.my_table (field_1, field_2, field_3, ... field_32)
VALUES(data_set1),(data_set2),(data_set3)...(data_set500)
ON DUPLICATE KEY UPDATE
field_1=VALUES(field_1), field_2=VALUES(field_2), field_3=VALUES(field_3) ... field_32=VALUES(field_32)
I've looked up this issue and normally it seems to happen when the user explicitly sets bind parameters and one is missing, but I don't understand why it's happening with my code where I don't set any, and I have no field name 'D' or know what that 'D' is even referring to. Also, to make things more confusing, when I plug in the EXACT same statement into MySQL Workbench, it executes with no problems.
I'm thinking the issue might stem from trying to send too much data at the same time, because I am trying to update/insert a lot of data with a lot of fields each. But if that's the case, how much is too much data since I don't want to be splitting this into 500+ individual inserts?