[Tutor] updating databases with null values

Rance Hall ranceh at gmail.com
Thu Dec 9 17:46:34 CET 2010


I have a set of questions that ask about a customers name, address, email, etc.

some of these values are allowed to be null, and others aren't.  Some
are required to have specific formats when they aren't null.

I'm happy with the code Ive written and its question asking routine,
but I need help understanding how best to deal with null values.

I'm connecting to a postgres database with the python postgres module
described here: http://python.projects.postgresql.org/

I'm also using python 3.x if it matters.

The sql is different if you want to allow null values

update table set value = "string" where condition

with null value:

update table set value = NULL where condition

It would seem I need several iterations of the prepared db statement
for various combinations of null values or I don't allow null values
at all and put empty strings in the database instead of the null
value.

Could someone help me think through this idea and help me decide on a
good method.  Right now I'm thinking that I should skip null values
and just store zero length strings in the db.  I don't like it, but
its certainly much easier (at least to me so far)

Your thoughts?


More information about the Tutor mailing list