Spaces:
Paused
Paused
Commit
•
49b296c
1
Parent(s):
f2740a4
overwrite the row if it already exists
Browse files- db/db_utils.py +24 -2
db/db_utils.py
CHANGED
@@ -185,8 +185,30 @@ def store_result_to_db(cursor, conn, run_key, result):
|
|
185 |
def store_results_batch(cursor, conn, run_key, results_batch):
|
186 |
logging.info(f"Storing batch of length {len(results_batch)}")
|
187 |
cursor.executemany('''
|
188 |
-
INSERT INTO results (
|
189 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
190 |
''', [
|
191 |
(
|
192 |
run_key,
|
|
|
185 |
def store_results_batch(cursor, conn, run_key, results_batch):
|
186 |
logging.info(f"Storing batch of length {len(results_batch)}")
|
187 |
cursor.executemany('''
|
188 |
+
INSERT INTO results (
|
189 |
+
run_key, run_row, date, input_word, dictionary_word, is_food, wweia_category, dry_matter_content, leakage, weight, weight_metric_tonnes, donor, similarity_score, food_nonfood_score, distance, ef, mt_lb_mile, baseline_emissions, leakage_emissions, project_emissions, total_emissions_reduction
|
190 |
+
) VALUES (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)
|
191 |
+
ON CONFLICT (run_key, run_row)
|
192 |
+
DO UPDATE SET
|
193 |
+
date = EXCLUDED.date,
|
194 |
+
input_word = EXCLUDED.input_word,
|
195 |
+
dictionary_word = EXCLUDED.dictionary_word,
|
196 |
+
is_food = EXCLUDED.is_food,
|
197 |
+
wweia_category = EXCLUDED.wweia_category,
|
198 |
+
dry_matter_content = EXCLUDED.dry_matter_content,
|
199 |
+
leakage = EXCLUDED.leakage,
|
200 |
+
weight = EXCLUDED.weight,
|
201 |
+
weight_metric_tonnes = EXCLUDED.weight_metric_tonnes,
|
202 |
+
donor = EXCLUDED.donor,
|
203 |
+
similarity_score = EXCLUDED.similarity_score,
|
204 |
+
food_nonfood_score = EXCLUDED.food_nonfood_score,
|
205 |
+
distance = EXCLUDED.distance,
|
206 |
+
ef = EXCLUDED.ef,
|
207 |
+
mt_lb_mile = EXCLUDED.mt_lb_mile,
|
208 |
+
baseline_emissions = EXCLUDED.baseline_emissions,
|
209 |
+
leakage_emissions = EXCLUDED.leakage_emissions,
|
210 |
+
project_emissions = EXCLUDED.project_emissions,
|
211 |
+
total_emissions_reduction = EXCLUDED.total_emissions_reduction
|
212 |
''', [
|
213 |
(
|
214 |
run_key,
|