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?

asked Feb 14, 2019 at 10:05

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)
answered Feb 14, 2019 at 10:09
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,))
answered Feb 14, 2019 at 10:18

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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.