Shakti
Shakti

Reputation: 2033

How convert None to NULL with Python 2.7 and pyodbc

I am passing the output from a sql query to again insert the data to ms sql db. If my data is null python / pyodbc is returning None instead of NULL. What is the best way to convert None to NULL when I am calling another query using the same data. Or a basic string transformation is the only way out ? Thanks Shakti

Upvotes: 8

Views: 21589

Answers (2)

Gord Thompson
Gord Thompson

Reputation: 123399

If you use a parameterized query to perform the insert then you won't have to worry about converting None to NULL (among other benefits). See my recent answer to a related question for details.

Upvotes: 11

Bartłomiej Bartnicki
Bartłomiej Bartnicki

Reputation: 1165

You could overwrite query function in way that None will be replace with "NULL"

Upvotes: -2

Related Questions