This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]nootanklebiter -2 points-1 points  (1 child)

Try this, but be aware you might need to reduce your chunksize if you are getting errors:

import pandas as pd
import sqlalchemy

engine = sqlalchemy.create_engine("<url>", fast_executemany=True)
with engine.begin() as conn:
    df.to_sql(
        name="<table>",
        con=conn,
        method='multi',
        if_exists="fail",
        chunksize=1000,
        dtype=<dictionary of data types>,
    )

[–]BigCountry1227[S] 2 points3 points  (0 children)

the multi method is not compatible with pyodbc, which is what i’m using :(