From 7f96fc68dab9b73ed44d13a1363d68854a3beed8 Mon Sep 17 00:00:00 2001 From: Michaela Ockova Date: Sat, 25 Jan 2020 16:32:49 +0100 Subject: [PATCH] Fix unique constraint error --- gtfspy/import_loaders/stop_times_loader.py | 2 +- gtfspy/import_loaders/table_loader.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/gtfspy/import_loaders/stop_times_loader.py b/gtfspy/import_loaders/stop_times_loader.py index 59e1a52..ac7a76d 100644 --- a/gtfspy/import_loaders/stop_times_loader.py +++ b/gtfspy/import_loaders/stop_times_loader.py @@ -57,7 +57,7 @@ def index(cls, cur): # This is used for the stop frequencies analysis. #cur.execute('CREATE INDEX idx_stop_times_tid_ath_sid ON stop_times (trip_I, arr_time_hour, stop_id)') # ^-- much slower than the next index. - cur.execute('CREATE INDEX idx_stop_times_ath_tid_sid ON stop_times (arr_time_hour, trip_I, stop_I)') + cur.execute('CREATE INDEX IF NOT EXISTS idx_stop_times_ath_tid_sid ON stop_times (arr_time_hour, trip_I, stop_I)') # This has now been moved to DayTripsMaterializer, but is left # here in case we someday want to make DayTripsMaterializer diff --git a/gtfspy/import_loaders/table_loader.py b/gtfspy/import_loaders/table_loader.py index b09ef1e..d181c88 100644 --- a/gtfspy/import_loaders/table_loader.py +++ b/gtfspy/import_loaders/table_loader.py @@ -279,7 +279,7 @@ def insert_data(self, conn): # proceed. Since there is nothing to import, just continue the loop print("Not importing %s into %s for %s" % (self.fname, self.table, prefix)) continue - stmt = '''INSERT INTO %s (%s) VALUES (%s)''' % ( + stmt = '''INSERT OR REPLACE INTO %s (%s) VALUES (%s)''' % ( self.table, (', '.join([x for x in fields if x[0] != '_'] + self.extra_keys)), (', '.join([":" + x for x in fields if x[0] != '_'] + self.extra_values))