title: fast_executemany alternative for psycopg2
body: <p>I have a Redshift server, which I initiate via psycopg2 (note that ODBC is not supported on the company server so I cant use pyodbc).</p>
  
  <p>Currently it is taken over 10 minutes for 30-35k rows via <code>pd.to_sql()</code>, which writes from dataframe into the Redshift DB. So as a work-around I download DF as csv, push file to S3, and then use <code>copy</code> to write into the DB.</p>
  
  <p>The <code>fast_executemany</code> solution as per <a href="https://stackoverflow.com/questions/48006551/speeding-up-pandas-dataframe-to-sql-with-fast-executemany-of-pyodbc">Speeding up pandas.DataFrame.to_sql with fast_executemany of pyODBC</a> would have been perfect- however this is not supported in <code>psycopg2</code>. 
  I also found <code>d6tstack</code> as per <a href="https://github.com/d6t/d6tstack/blob/master/examples-sql.ipynb" rel="noreferrer">https://github.com/d6t/d6tstack/blob/master/examples-sql.ipynb</a> but <code>pd_to_psql</code> doesn't work for Redshift, only Postgresql (can't <code>copy... from stdin</code>)</p>
  
  <p>Any alternatives I can use for my case?</p>
  
  <p>This is my code:</p>
  
  <pre><code>import sqlalchemy as sa
  
  DATABASE = ""
  USER = ""
  PASSWORD = ""
  HOST = "...us-east-1.redshift.amazonaws.com"
  PORT = "5439"
  SCHEMA = "public" 
  
  server = "redshift+psycopg2://%s:%s@%s:%s/%s" % (USER,PASSWORD,HOST,str(PORT),DATABASE)
  engine = sa.create_engine(server)
  conn = engine.raw_connection()
  
  with conn.cursor() as cur:
      cur.execute('truncate table_name')
  
  df.to_sql('table_name', engine, index=False, if_exists='append') 
  </code></pre>