Advertisement
Guest User

Untitled

a guest
Aug 21st, 2019
75
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.46 KB | None | 0 0
  1. from sqlalchemy import create_engine
  2.  
  3. # Port 5439 for Redshift
  4. engine = create_engine("postgresql://user@localhost:5432/mydb")
  5. df = pd.read_sql_query("select * from airlines", engine)
  6.  
  7. # Get results in chunks
  8. for chunk in pd.read_sql_query("select * from airlines", engine, chunksize=5):
  9. print(chunk)
  10.  
  11. # Writing back
  12. df.to_sql(
  13. "table"
  14. schema="schema"
  15. # fail, replace or append
  16. if_exists="append",
  17. # write back in chunks
  18. chunksize = 10000
  19. )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement