0

I am using to_sql to append a table into Oracle. However, I am getting the following error

(cx_Oracle.DatabaseError) ORA-01843: not a valid month [SQL: 'INSERT ... INTO

I tried to define the type of column for the date columns in the table

 d_type_date = {c: types.DateTime for c in
                   data.columns[data.dtypes.isin(['datetime64[ns]', '<M8[ns]'])].tolist()}

And then pass it as a parameter to_sql

        self.final_data.to_sql(table
              , con=connection
              , schema=schema
              , if_exists='append'
              , index=False
              , dtype=d_type_date)

But I am still getting the same error. I read that it might be NLS_DATE_FORMAT, but I am not sure how to overcome the issue

Ilja Everilä
  • 50,538
  • 7
  • 126
  • 127
Santiago
  • 57
  • 1
  • 6
  • How are you supplying the value to the insert statement? Well, apparently as a string, as there implicit conversion is failing... but in a way that you can wrap it in an explicit `to_date()`, or can you bind it as an actual date instead? – Alex Poole Dec 18 '18 at 16:39
  • yep you are right, I had one column containing a date that was being passed as a string, thank you so much, I fixed the issue – Santiago Dec 18 '18 at 16:54

0 Answers0