I am struggling a bit with figuring out how I can alter mysql column names in python.
Below is what I ideally want to do:
column_name = "Kills"
my_cur.execute("alter table match_historical_player_stats add column_name float ")
Can someone help me create the correct syntax to solve this problem?
asked Feb 14, 2019 at 10:05
MathiasRa
8652 gold badges12 silver badges28 bronze badges
2 Answers 2
You can try this here:
column_name = "Kills"
query = "ALTER TABLE match_historical_player_stats ADD {} FLOAT".format(column_name)
my_cur.execute(query)
answered Feb 14, 2019 at 10:09
madik_atma
7991 gold badge12 silver badges31 bronze badges
Sign up to request clarification or add additional context in comments.
Comments
You should use a prepared statement, rather that python formatting. This will make sure that everything is escaped properly.
column_name = "Kills"
query = "ALTER TABLE match_historical_player_stats ADD %s FLOAT"
my_cur.execute(query, (column_name,))
answered Feb 14, 2019 at 10:18
Jim Wright
6,0781 gold badge18 silver badges35 bronze badges
Comments
default