Массовое обновление в PostgreSQL с помощью psycopg2 не работаетPython

Программы на Python
Anonymous
Массовое обновление в PostgreSQL с помощью psycopg2 не работает

Сообщение Anonymous »

Код: Выделить всё

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

Вернуться в «Python»