Home > front end >  Python SQLite3 - INSERT-WHERE Workaround
Python SQLite3 - INSERT-WHERE Workaround

Time:01-13

I am using SQLite3 with Python. I am quite certain that the 'WHERE' clause does not work with 'INSERT' operation, but I really need to have a workaround to solve my issue. I have the following prepopulated database:

enter image description here

I was hoping to come up with an SQL statement where I can add the VALUES ('2021-01-13', '36.8') to the table WHERE family='FAA' AND model='MAA'. I have read a lot of stuff online but still no luck on my side.

CodePudding user response:

I think you want an update here:

UPDATE yourTable
SET date = '2021-01-13', duration = 36.8
WHERE family = 'FAA' AND model = 'MAA';

CodePudding user response:

You want to update your table, insert is only for new rows. When you want to change a value, you must to use update statement.

UPDATE table_name
   SET date = '2021-01-13', duration = '36.8'
 WHERE  family='FAA' AND model='MAA';

https://www.sqlite.org/lang_update.html

  •  Tags:  
  • Related