aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTimo Wilken2024-08-25 11:25:38 +0200
committerTimo Wilken2024-08-25 11:25:38 +0200
commit31bceab35953c1e8b9f4ace45af49b901e939441 (patch)
tree74a0890bef0809c34ce06eb7a83c13810db5b773
parentf1328a5b750ba3ad55f9c3e29cd8ea926bf4523b (diff)
Upsert electricity values
If a value already exists for a specific time, this normally causes an error. Replace the value instead.
-rw-r--r--tw/services/personal-data-exporter.scm3
1 files changed, 2 insertions, 1 deletions
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
(($ <data-point> 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))