You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The most notable change I faced was the removal of copy_expert. Here is a psql_insert_copy method for uploading a pandas dataframe to the database which I updated for psycopg3. Hopefully it helps.
'''Alternative to_sql() *method* for DBs that support COPY FROM'''importcsvfromioimportStringIOdefpsql_insert_copy(table, conn, keys, data_iter):
""" Execute SQL statement inserting data Parameters ---------- table : pandas.io.sql.SQLTable conn : sqlalchemy.engine.Engine or sqlalchemy.engine.Connection keys : list of str Column names data_iter : Iterable that iterates the values to be inserted """# gets a DBAPI connection that can provide a cursordbapi_conn=conn.connectionwithdbapi_conn.cursor() ascur:
s_buf=StringIO()
writer=csv.writer(s_buf)
writer.writerows(data_iter)
s_buf.seek(0)
columns=', '.join([f'"{k}"'forkinkeys])
iftable.schema:
table_name=f'{table.schema}.{table.name}'else:
table_name=table.namesql=f'COPY {table_name} ({columns}) FROM STDIN WITH CSV'withcur.copy(sql) ascopy:
whiledata:=s_buf.read(10240):
copy.write(data)
Is there a plan to add support for https://www.psycopg.org/psycopg3/docs/index.html?
The text was updated successfully, but these errors were encountered: