Python Forum

Full Version: Inserting a variable as column name in sqlite3 python
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
So how exactly do you do it? I have tried doing this -
'UPDATE Table SET {} WHERE name=?'.format(col) , [name])
and this -
'UPDATE Table SET %s WHERE name=?' % (col,), [name]
Both have been giving me the error of
Error:
OperationalError: near "WHERE": syntax error
. Is this even possible?
use the verb ALTER
It will add the new column as last column (required to maintain integrity of old table.
see: https://www.sqlitetutorial.net/sqlite-alter-table/
(Oct-22-2020, 11:17 AM)Larz60+ Wrote: [ -> ]use the verb ALTER
It will add the new column as last column (required to maintain integrity of old table.
see: https://www.sqlitetutorial.net/sqlite-alter-table/

Alter creates a new column, I would like to use a variable to search and update a pre-existing column.
After SET you should assign a value to a column. The syntax is:
Update <table_name>
Set <Column_name> = <value>
where <column_name = <another_value>