Addressing Slow Write Speeds
When writing to Oracle, all df columns which are String objects are by default converted to CLOB (Character large objects), which are max 2,147,483,647 in length). This means that tables are very likely far larger than necassary.
When using df.to_sql, you typically use something like the following:
df.to_sql("tablename"
connection_string,
schema='myschema',
if_exists='replace',
index=False
)
However, omitting the optional parameter dtypes may result in CLOBs.
A Solution
To overcome this, you either manually provide dtypes:
df.to_sql("tablename"
connection_string,
schema='myschema',
if_exists='replace',
index=False,
dtype={"RUN_DT": sa.types.DateTime(),
"fname": sa.types.VARCHAR(length=50),
"lname": sa.types.VARCHAR(length=250),
"FROM_DT": sa.types.DateTime(),
"TO_DT": sa.types.DateTime(),
"UUID": sa.types.VARCHAR(length=50)}
)
A Better, Generalized Solution
But what if you have many tables and many columns and you need a generalized solution?
@Parfait provided the perfect solution to this issue on SO here.