0

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?

2 Answers 2

1

You can try this here:

column_name = "Kills"
query = "ALTER TABLE match_historical_player_stats ADD {} FLOAT".format(column_name)

my_cur.execute(query)
Sign up to request clarification or add additional context in comments.

Comments

0

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,))

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.