Skip to content

Commit

Permalink
Fix write_data and write_uid info when update curve
Browse files Browse the repository at this point in the history
  • Loading branch information
oriolpiera committed Nov 2, 2023
1 parent dbdfb1a commit 38d4c8e
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion cchloader/backends/timescaledb.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit 38d4c8e

Please sign in to comment.