1

How can I update a record in a database based on a variable?

I have a variable named run_time_start that is previously sent to the database.

But then, at some point, I want to update 2 columns in the same record, with the values of the variables end_date and total_time

is there any way I can do something like this?

engine.execute("UPDATE control_general_log SET (end_date, total_time) VALUES (?, ?)", run_time_end, total_elapsed_time, "WHERE chain_script = ?", run_time_start)

1 Answer 1

1

try this:

engine.execute("UPDATE control_general_log SET end_date=?, total_time=? WHERE chain_script = ?", (run_time_end, total_elapsed_time, run_time_start,)

conn.commit()  # conn is your connection variable
Sign up to request clarification or add additional context in comments.

3 Comments

As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers in the help center.
It didn't raise any error but it also didn't write to the db
make sure u use commit(), i dont know how u call to your connection object ( the one u use to generete the "engine" cursor)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.