I just want only a certain date to be insert into my table. I have this code.
When I used only this code, all of data in csv inserted
for row in readers:
query4 = """INSERT INTO csv(
csv_id, Mchn, EnNO, Mode1,
IODMd, Date_Time)
VALUES(%s,%s,%s,%s,%s,%r)
"""
db.session.execute(query4 % (row[0], row[1], row[2], row[4], row[5], row[6],))
db.session.commit()
but I want only a certain date to be insert so I try this add WHERE on it. Like this
for row in readers:
query4 = """INSERT INTO csv(
csv_id, Mchn, EnNO, Mode1,
IODMd, Date_Time)
VALUES(%s,%s,%s,%s,%s,%r)
WHERE Date_Time >= (select c_start_date from c_temp c where c.id = :id)
AND Date_Time <= (select DATE_ADD(c_end_date,interval 1 day) from c_temp c where c.id = :id)"""
db.session.execute(query4 % (row[0], row[1], row[2], row[4], row[5], row[6],))
db.session.commit()
But when I try it, it has an error and stop it. Thank you.
query4is only executing the last row, and not each row. I would probably generate the SQL insert statements and put the created strings in a list, then create a single transaction to INSERT.