Python Forum

Full Version: Pymysql delete specific rows in tableview
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
There is a database, data is constantly written to it, but sometimes data 0.0 gets. An entry appears in the table with values, for example prod1=0.0/ prod2=0.0/ prod3=0.0. And there can be a lot of such records in a day. I would like to make a python script that will be run by cron and delete all entries from 0.0. But there is data like: prod1=34.2/ prod2=0.0/ prod3=0.0 this line should be left.
(Aug-18-2022, 08:15 AM)stsxbel Wrote: [ -> ]An entry appears in the table with values, for example prod1=0.0/ prod2=0.0/ prod3=0.0. And there can be a lot of such records in a day. I would like to make a python script that will be run by cron and delete all entries from 0.0. But there is data like: prod1=34.2/ prod2=0.0/ prod3=0.0 this line should be left.

To me, this is a contradiction: delete prod2=0.0 / prod3=0.0 but prod2=0.0 / prod3=0.0 should be left ??!!

I work with a SQL database every day and the best way to keep the data clean, is to not have any garbage written to it. As the saying goes: GIGO
I agree with Rob101, it is best to prevent unwanted data to be written to the database.
But if this cannot be done, you will need to execute the following regularly.
delete from TABLENAME
where PROD1 = 0.0
  and PROD2 = 0.0
  and PROD3 = 0.0 ;

commit ;