Unable to have null value for date while reading data from excel sheet using python and saving in postgres database

  dataframe, pandas, python-3.x, sqlalchemy, xlrd

In excel sheet i have a Date column that can be null so i am using xlrd to read data from the sheet and using

df.to_sql(
    con=engine,
    name=table.__tablename__,
    index=False,
    if_exists='append'
)

to append to postgres database when i try i get

   sqlalchemy.ex.DataError:(psycopg2.errors.InvalidDateTimeFormat) invalid input syntax for type date: ""
    Line1 Insert into (1,2,3,'name','')
                                       ^

I have tried adding NULL while creating the table as

cursor.execute(
CREATE TABLE(
   ID1 INTEGER,
    ID2 INTEGER,
    ID3 INTEGER,
    Name TEXT,
    DateRequired Date NULL
)
)

In anyway i can store null value or blank value for date column in excel sheet and append that null value to database as well?

Source: Python-3x Questions

LEAVE A COMMENT