SQL null conversion

Jeff Sacksteder jwsacksteder at ramprecision.com
Wed Jan 22 17:23:51 CET 2003


I am moving/converting data from a production system to a data warehouse
using python for the data transformation. I iterate through the result list
building sql strings to do the inserts that then get sent to the destination
connection. Occasionally I hit a row where a feild is null, returning
'None'. When I try to build a string containing 'None' I get an exception.
What would be the best way to convert that to an empty string in the general
case? 

---snippet---

source_extract = "select foo,bar,baz from datatable"
source.execute(source_extract)
result_set = source.fetchall()

for row in result_set:
	# in reality, each feild here is being cleaned up in various ways-
not shown for clarity
	insert_string = "insert into dest values (' " + row[0] + " ',' " +
row[1] +" ',' " + row[3] +" ')"
	dest.execute(insert_string)





More information about the Python-list mailing list