Код: Выделить всё
def update_database(self, results):
try:
length = len(self.unique_ids)
update_data = [(self.unique_ids[i], results[i]) for i in range(length)]
query = """
UPDATE public.post_data AS p
SET content = t.content
FROM (VALUES %s)
AS t (unique_id, content)
WHERE p.unique_id = t.unique_id;
"""
template = '(%s, %s)'
execute_values(self.cursor, query, update_data, template=template)
self.conn.commit()
logging.info("Successfully Updated")
except Exception as error:
logging.warning(f"Update Error -> {error}")
finally:
self.conn.close()
self.cursor.close()
Подробнее здесь: https://stackoverflow.com/questions/788 ... oesnt-work