MySQL Forums
Forum List  »  Connector/Python

Using Column Names as a Variable
Posted by: Drew Waite
Date: June 26, 2020 03:10PM

First Post!

Thank you in advance for helping me with this question that I promise am not trying to make difficult.

I am writing a python script on my PI to connect to my SQL database on a subscription hosting site with a Cpanel. My program is grabbing an API from a gambling site to see the over/under on every sports game(that i care about) every hour and recording the hourly difference from the previous hour before the event. My hours are from 60 hours before the game to 0 hours before.

I can easily create a CSV and access it there, but my problem comes when I try to log it into SQL.

I am finding myself with 60 + columns in my table that I am trying to fill with odds.

Now the problem:

I have 60+ columns I need to fill with odds..

Each sport has a unique game ID that I have set as my primary key. Instead of updating every column in the row that I would like to update, is it possible to use a variable to find the column I want?

Right now my columns are labeled 60, 59, 58, 57, 56, 55...etc then the values of the rows hold the over/under at that hour leading up to the match.

Is there any way that I can use my HOURSBEFOREMATCH integer as a variable to use that as a variable as a column name to INSERT it in the correct place?

Hope this makes sense..

Thanks alot guys!

Options: ReplyQuote

Written By
Using Column Names as a Variable
June 26, 2020 03:10PM

Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.