Update multiple columns at the same time
See original GitHub issueHello,
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:
- Created 5 years ago
- Comments:6 (2 by maintainers)
Top 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 >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Is this the best way to create an update statement with multiple sets?
@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 oftest_update_query.set(key, columns_test[key])