[DB-SIG] PyGreSQL and NULLs

Marc Colosimo mcolosimo at mitre.org
Tue Feb 10 17:20:00 EST 2004


On Feb 10, 2004, at 5:01 PM, Chris Cogdon wrote:
>
> On Feb 10, 2004, at 13:49, Marc Colosimo wrote:
>
>> oops, I forgot to add that in my pseudo code. Here is a real example. 
>> As you see it puts in None, instead of Null. If I change "pet":None 
>> to "pet":"Null" it works.
>
> Actually, you'll find that it doesn't work. It inserts the string 
> "Null" rather than the 'null object', which are very, very different.
>
> I would actually consider this to be a 'misfeature' that the data type 
> converter does not convert the python None object into the DB NULL 
> object.
>
>
I changed the table for my_pet_id to:

my_pet_id INTEGER UNIQUE

then added another person:

my_user = {"id":11,"name":"Chris","pet":"Null"}

%psql test
test=# select * from mytable ;
  my_id | my_name | my_pet_id
-------+---------+-----------
     10 | Marc    |
     11 | Chris   |
(2 rows)

Better yet,

test=# select * from mytable where my_pet_id IS NULL;
  my_id | my_name | my_pet_id
-------+---------+-----------
     10 | Marc    |
     11 | Chris   |
(2 rows)


Marc





More information about the DB-SIG mailing list