From 38d4c8e1999a2a2e6db3b039d9aff516eba441af Mon Sep 17 00:00:00 2001 From: Oriol Piera Date: Thu, 2 Nov 2023 12:23:58 +0100 Subject: [PATCH] Fix write_data and write_uid info when update curve --- cchloader/backends/timescaledb.py | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/cchloader/backends/timescaledb.py b/cchloader/backends/timescaledb.py index a790548..698a1f2 100644 --- a/cchloader/backends/timescaledb.py +++ b/cchloader/backends/timescaledb.py @@ -87,11 +87,19 @@ def insert_cch_batch_chunk(self, collection, batch): field_names = unique_batch[0].keys() data = [vals.values() for vals in unique_batch] + fields_to_update = [] + for field in field_names: + if field in ['name', 'utc_timestamp', 'create_date', 'create_uid']: + continue + else: + fields_to_update.append('{}=EXCLUDED.{}'.format(field, field)) + fields_to_update.append('write_date=EXCLUDED.create_date') + fields_to_update.append('write_uid=EXCLUDED.create_uid') sql = "INSERT INTO {} ({}) VALUES %s ON CONFLICT (name, utc_timestamp) DO UPDATE SET {};".format( collection, ','.join(field_names), - ', '.join(['{}=EXCLUDED.{}'.format(field, field) for field in field_names]) + ', '.join(fields_to_update) ) psycopg2.extras.execute_values(self.cr, sql, data, template=None, page_size=9999)