From 31bceab35953c1e8b9f4ace45af49b901e939441 Mon Sep 17 00:00:00 2001 From: Timo Wilken Date: Sun, 25 Aug 2024 11:25:38 +0200 Subject: Upsert electricity values If a value already exists for a specific time, this normally causes an error. Replace the value instead. --- tw/services/personal-data-exporter.scm | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tw/services/personal-data-exporter.scm b/tw/services/personal-data-exporter.scm index fb998459..18a048e1 100644 --- a/tw/services/personal-data-exporter.scm +++ b/tw/services/personal-data-exporter.scm @@ -100,7 +100,8 @@ completely managed by @code{personal-data-exporter-service-type}.")) (match-lambda (($ date value) (let ((date-type (if (string-contains date " ") "timestamp" "date"))) - (dbi-query db (format #f "insert into \"~a\" values (~a '~a', ~a);" + ;; If a value already exists for any given point in time, replace it. + (dbi-query db (format #f "insert into \"~a\" values (~a '~a', ~a) on conflict (\"time\") do update;" table date-type date value)))))) (let ((settings (call-with-input-file #$conso-config-file json->settings)) -- cgit v1.2.3