pyodbc - problem passing None as parameter

Frank Millman frank at
Fri Oct 23 11:16:32 CEST 2009

Tim Goldenwrote:
> Frank Millman wrote:
>> I want the final WHERE clause to show 'WHERE todate IS NULL'.
> Of course, I understand that. What I mean is that if a piece
> of SQL say:
>  WHERE table.column IS ?
> then the only possible (meaningful) value ? can have is
> NULL (or None, in python-speak). In fact, the IS NULL is
> really a sort of unary operator-expression, not an operator
> with a value.

>> As a workaround, I suppose I could scan the argument list, and if I find 
>> a None, substitute the ? with NULL in the SQL statement itself.

> Well, the code I posted previously, although tedious taken to
> extremes, will do that. (I have seen and used code like that in a number 
> of production systems).

Thanks, Tim, for the detailed explanation. I appreciate your taking the 

It was difficult for me to use the code that you posted, because under my 
present setup I define my SQL statements externally, and the WHERE clause 
has to conform to one or more rows of six columns -
    Test (WHERE or AND or OR)
    Left bracket (either present or blank)
    Column name
    Right bracket (either present or blank)

I therefore used the workaround that I mentioned above, and it seems to work 
fine, for both pyodbc and psycopg2.

Once again, many thanks.


More information about the Python-list mailing list