瀏覽代碼

Fix database unique issue

Foppe Hemminga 6 年之前
父節點
當前提交
18a006e352
共有 1 個文件被更改,包括 3 次插入1 次删除
  1. 3 1
      main.py

+ 3 - 1
main.py

@@ -110,7 +110,9 @@ if __name__ == '__main__':
                 if broadcast:
                     view.broadcast(message)
                 # store new scratching
-                query = "INSERT INTO horses(venue, race_date, race, horse) VALUES(%s, %s, %s, %s)"
+                query = """INSERT INTO horses(venue, race_date, race, horse) 
+                    VALUES(%s, %s, %s, %s)
+                    ON CONFLICT(venue, race_date, race, horse) DO NOTHING;"""
                 cursor.execute(query, (scratching.venue, scratching.date,
                                        scratching.race, scratching.horse))
                 db.commit()