N
N
nnikolyaa2020-08-19 19:30:20
Python
nnikolyaa, 2020-08-19 19:30:20

Can I do that?

I have many columns in a table.
And in order not to write my own UPDATE for each, can I specify what exactly to update?

cur.execute(f"UPDATE users SET ? = ? WHERE user_id=? AND chat_id=?")
cur.commit()

And if I can’t, are there any other, more beautiful ways than stupidly copying?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
R
Ruslan., 2020-08-19
@LaRN

You can try this, but it won't cut your code that much:
cur.execute(f"UPDATE users SET field1=?, field2=?, fieldN=? WHERE user_id=? AND chat_id=?")

V
Valery Mamontov, 2020-08-20
@vmamontov

nnikolyaa , try using executemany() or executescript() instead of execute ( )

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question