Reputation: 91
Question is what's written on the tin. I currently have a project I am working on with the current workflow:
I have been able to squeeze some extra efficiency into the loop by running concurrent.futures on the keyterm search (step 2 and 3), which allows me to run all cores simultaneously. Now I wanted to see if I could get some extra efficiency out of the loop by speeding up the database calls (step 1)
Here is my current code
import psycopg2
conn = pg.connect(
host=host,
database=database,
username=username,
password=password
)
SQLselect= '''
select *
from {}
'''
for databese in databases:
cur=conn.cursor('database')
call=cur.execute(SQLselect.format(database))
rows=cur.fetchall
cols=[desc[0] for desc in cur.description]
temp = pd.DataFrame(rows, columns=cols
Instead of this method, I also tried using psycopg2's copy_to method. I figured this would be faster, since the copy_from method works so well. However, this actually ended up being slower than the code I have above. Is there any way I could speed this up or do this more efficiently?
Upvotes: 3
Views: 1958