[DB-SIG] PyGreSQL and NULLs

Dieter Maurer dieter at handshake.de
Tue Feb 10 13:56:59 EST 2004


Marc Colosimo wrote at 2004-2-9 15:44 -0500:
>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?

What happens when you use

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

?

-- 
Dieter



More information about the DB-SIG mailing list