I'm generating a sql file with insert statements with a python script, but I don't know how to insert NULL values.
I have a dictionary where keys are the name of the columns and the values the values I want to insert. For example:
d = {"column1":"1", "column2":"test", "column3":None}
Then I want to use that values in my insert statement.
sqlfile.write("INSERT INTO test VALUES ('" + d["column1"] + "', '" + d["column2"] + "', '" + d["column3"] + "')")
But this will return an error because non type and strings cannot be concatenated and if I replace None by 'NULL' it will insert a 0 in database.
How can I solve this?
sqlfile.write("INSERT INTO test VALUES ('1','test', NULL)")inserts an actual NULL.