question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Update multiple columns at the same time

See original GitHub issue

Hello,

Thanks for this very useful tool. I wanted to dynamically update multiple columns at the same time through a loop but I didn’t figure how to do it. Here is an simple example that I tried

columns = {"key1" : "value1", "key2 : "value2"}
update_query = Query.update(table_to_update).where(table_to_update.id == 1)
for key in columns:
    update_query.set(key, columns[key])

A str(update_query) returns an empty string when I was expecting an UPDATE query with key1 and key2 and I saw that the __updates has been reinitialized to []

Is there a solution for this issue?

Thanks

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
andreamorocommented, Dec 3, 2020

Is this the best way to create an update statement with multiple sets?

1reaction
mikeenglandcommented, May 22, 2018

@alamart you are missing the extra assignment @inkmix suggested.

The code you pasted above needs test_update_query = test_update_query.set(key, columns_test[key]) instead of test_update_query.set(key, columns_test[key])

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to Update Multiple Columns in Single Update Statement ...
In this article, we will see, how to update multiple columns in a single statement in SQL. We can update multiple columns by...
Read more >
Update multiple columns in SQL - Stack Overflow
Try this: UPDATE table1 SET a = t2.a, b = t2.b, ....... FROM table2 t2 WHERE table1.id = t2.id. That should work in...
Read more >
SQL UPDATE Statement (Transact SQL) - Essential SQL
To update multiple columns use the SET clause to specify additional columns. Just like with the single columns you specify a column and...
Read more >
Update Multiple Columns in SQL - Scaler Topics
We can update multiple columns in SQL using the UPDATE command. The UPDATE statement is followed by a SET statement, which specifies the...
Read more >
SQL UPDATE - Dofactory
One way to update multiple rows is to write multiple UPDATE statements. They can be separated with a semicolon (;) and submitted as...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found