I am currently joining two lists together in python to generate a string for input into a database using this code:
newDataString = ', '.join("%s=\'%s\'" % t for t in zip(tableColumns,data))
where tableColumns is a list of columns, and data is a list of data related to the columns. I am joining these together to perform an update.
It all works fine, except in cases where a value in the data list = None
cur.execute("UPDATE "+table+" SET "+str(newDataString)+" FROM "+tempTable+" WHERE "+generatePrimaryKeyMatches(primaryKey, table))
psycopg2.DataError: invalid input syntax for type date: "None"
LINE 1: ...ION RESEARCH & REP', suff='None', hon='None', dob='None', na...
I suppose I need an if statement in here somewhere to check every value in data before I put it into the join, and it should be treated differently (i.e. no \') if data = None, but I cannot for the life of me figure it out.
Any help greatly appreciated.