I am trying to update Count=Count+1
if src_ip
already exists, else insert into table.
I was able to do it with UPSERT successfully:
INSERT INTO result('min(_time)', src_ip) VALUES(?,?)ON CONFLICT(src_ip) DO UPDATE SET Count=Count+1;
I am looking for another way to do this without using UPSERT. I tried this :
# Import csv to SQLite
with open('result5.csv', 'r') as f:
dr = csv.DictReader(f)
for i in dr:
c.execute("UPDATE result SET Count = Count + 1 WHERE src_ip = ?", (i['src_ip'],))
if c.rowcount == 0:
c.execute("INSERT INTO result ('min(_time)', src_ip, Count) VALUES (?,?,1)",
(i['min(_time)'], i['src_ip']))
The script works with no errors. But I am not getting the result I want either. It does not return anything sadly. I am not sure what I am doing wrong here, why can't I UPDATE
or INSERT
?
Thank you.