Skip to content

Commit

Permalink
bugfix clean_dupplicates (untested)
Browse files Browse the repository at this point in the history
  • Loading branch information
ThomasLecocq committed Jul 30, 2024
1 parent 49641ce commit fa3b043
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions msnoise/scripts/msnoise.py
Original file line number Diff line number Diff line change
Expand Up @@ -416,14 +416,14 @@ def db_clean_duplicates():
prefix = (dbini.prefix + '_') if dbini.prefix != '' else ''
db = connect()
if dbini.tech == 1:
query = 'DELETE FROM {0}jobs WHERE rowid NOT IN '\
'(SELECT MIN(rowid) FROM {0}jobs GROUP BY day,pair,jobtype)'\
.format(prefix)
# SQlite case
query = "WITH cte AS (SELECT *, ROW_NUMBER() OVER (PARTITION BY day, pair, jobtype ORDER BY ref) AS rn FROM {0}jobs) DELETE FROM {0}jobs WHERE ref IN (SELECT ref FROM cte WHERE rn > 1);".format(prefix)
elif dbini.tech == 2:
# Mysql/mariadb
query = "DELETE j1 FROM {0}jobs j1 INNER JOIN {0}jobs j2 ON j1.ref > j2.ref AND j1.day = j2.day AND j1.pair = j2.pair AND j1.jobtype = j2.jobtype;".format(prefix)
else:
query = 'DELETE from {0}jobs USING {0}jobs as j1, {0}jobs as j2 '\
'WHERE (j1.ref > j2.ref) AND (j1.day=j2.day) '\
'AND (j1.pair=j2.pair) AND (j1.jobtype=j2.jobtype)'\
.format(prefix)
# postgresql
query = "DELETE FROM {0}jobs WHERE ref NOT IN (SELECT MIN(ref) FROM {0}jobs GROUP BY day, pair, jobtype);".format(prefix)
db.execute(text(query))
db.commit()
db.close()
Expand Down

0 comments on commit fa3b043

Please sign in to comment.