SQL doesnt compare to NULL using the "=" operator, the "IS NULL"
construct must be used. Therefore there is no way for a bind
parameter to be used here. If you use implicit bind params, the
binds will be generated automatically as needed, e.g. "table.c.somecol
== myvalue" will generate "somecol = :param" or "somecol IS NULL"
based on the value of "myvalue". only use "bindparam()" if you need
to specify literal values at a later time than the statement is
constructed - in the example you posted that's not the case.
On May 14, 2009, at 9:15 PM, James wrote:
>
> Hi, sql.bindparam doesn't seem to play well with None values:
>
>>>> sel0 = resource_table.select(resource_table.c.lock_expires_at ==
>>>> bindparam('expires_at'))
>>>> conn.execute(sel0, expires_at=None).fetchall()
> []
>>>> sel1 = resource_table.select(resource_table.c.lock_expires_at ==
>>>> None)
>>>> conn.execute(sel1).fetchall()
> [(1L, u'00', '90f05d20755b4ca8813b4f957fb63b71', None)]
>
> Looking at the issued SQL, it seems a bindparam None value results in
> a "xxx = NULL", while the direct WHERE (sel1 above) results in a "xxx
> is NULL".
>
> Is it possible to get bindparam to work here?
>
> If not, is it bad practice / inefficient to recreate the statement per
> query, rather than create once and parameterise with bindparam?
>
> Thanks,
> James
> >
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"sqlalchemy" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/sqlalchemy?hl=en
-~----------~----~----~----~------~----~------~--~---