![]() |
Inserting a variable as column name in sqlite3 python - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Data Science (https://python-forum.io/forum-44.html) +--- Thread: Inserting a variable as column name in sqlite3 python (/thread-30469.html) |
Inserting a variable as column name in sqlite3 python - JellyCreeper6 - Oct-22-2020 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 . Is this even possible?
RE: Inserting a variable as column name in sqlite3 python - Larz60+ - Oct-22-2020 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/ RE: Inserting a variable as column name in sqlite3 python - JellyCreeper6 - Oct-26-2020 (Oct-22-2020, 11:17 AM)Larz60+ Wrote: use the verb ALTER Alter creates a new column, I would like to use a variable to search and update a pre-existing column. RE: Inserting a variable as column name in sqlite3 python - ibreeden - Nov-01-2020 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> |