pymysql query rate (for statement)

Asked 2 years ago, Updated 2 years ago, 110 views

try:
    with conn.cursor() as cursor:
        for i in range(0,len(Portfolio)):
            sql = 'Select Price_Div.Ticker, Price_Div.Date, Price_Div.Price_Div from Price_Div where Price_Div.Date = STR_TO_DATE(%s,\'%%Y%%m%%d\') and Price_Div.Ticker = \'' + Portfolio[i] + '\''  
            cursor.execute(sql,str(Date.year)+str(Date.strftime('%m'))+str(Date.strftime('%d')))
            rowsa = cursor.fetchall()
            rows = rows + rowsa
    conn.commit()

finally:

    conn.close() 

I ran the following code, but it seems to be taking a lot of time. Is there any way to save time?

pymysql

2022-09-21 10:18

1 Answers

...
where
...
and Price_Div.Ticker = \'' + Portfolio[i] + '\''

Try using in instead of =.


2022-09-21 10:18

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.