如何使用 python 中的变量 Sql Update Into?

How to Sql Update Into with variables in python?

连接和所有其他 sql 执行工作正常,但我的更新语句不是:

sql= "UPDATE table_name SET column2=%s, column3=%s WHERE column1=%s;"
values = (variable2, variable3, variable1)
cursor.execute(sql, values)

输出为none。

尝试使用 f 个字符串。

sql= f"UPDATE table_name SET column2={variable2}, column3={variable3} WHERE column1={variable1};"
cursor.execute(sql)

更新 sql 条目的最佳方法是“INSERT INTO ... ON CONFLICT”函数。

cursor.execute("""
            INSERT INTO tablename
            (column1, column2, column3)
            VALUES
                (%s, %s, %s)
            ON CONFLICT(column1) DO UPDATE
            SET
                column2=excluded.column2,
                column3=excluded.column3;
                   """, (Value1, Value2, Value3)
                       )