[DB-SIG] PyGreSQL and NULLs

Marc Colosimo mcolosimo at mitre.org
Mon Feb 9 15:44:45 EST 2004


I hope this list is alive. The DB-API 2.0 document says that "SQL NULL 
values are represented by Python None signleton on imput and output" 
under Type Objects and Constructors. However, when passing in a None 
object using the pyformat it replaces it with a blank string.

for example,

my_user = {"id":10,"name":"Marc"}

cursor.execute("INSERT into myTable (my_id, my_name, my_pet_id) values 
" +
			"(%(id)s,'%(name)s',%(pet)s) % my_user)

would result in this SQL command,

INSERT into myTable (my_id, my_name, my_pet_id) values (10, 'Marc', );

instead of this one

INSERT into myTable (my_id, my_name, my_pet_id) values (10, 'Marc', 
NULL);

is this a known problem?

Thanks
Marc





More information about the DB-SIG mailing list