On Tue, Dec 22, 2009 at 2:34 AM, jo <jose.soa...@sferacarta.com> wrote:

> Hi all,
>
> I'm trying to solve this error...
>
> File
> "/home/sfera/release/sicer/BASE/controller/controlli/sopralluogo.py",
> line 645, in verifiche
> Piano.c.data_inizio <=data.get('data_sop') ,
> File "/usr/lib/python2.4/site-packages/sqlalchemy/sql.py", line 1294, in
> __le__
> return self._compare('<=', other)
> File "/usr/lib/python2.4/site-packages/sqlalchemy/sql.py", line 1423, in
> _compare
> raise exceptions.ArgumentError("Only '='/'!=' operators can be used with
> NULL")
> ArgumentError: Only '='/'!=' operators can be used with NULL
>
> -------------------------------------
>
> here the code that originates the above error:
>
> sr = sa.and_(Piano.c.data_inizio <=data.get('data_sop') )
>
> I suppose data.get('data_sop') returns a None value, thus, sa compiles
> the query like so:
>
> where piano.data_inizio <= NULL
>
> Could someone give me, some suggest how to solve this problem?
> Thank you
>
>
 This is correct behavior for a SQL query since the only legal behavior for
NULL is IS NULL or IS NOT NULL.

First question to answer is what should your application do when data_sop is
NULL?
If you want to treat NULL same as zero, use a case() function to force null
to zero in the comparison. If NULL should not participate at all, put a
"!=None" check first in the and_condition to skip rows with NULL values.
There are probably other alternatives, but it all comes down to desired
behavior when the column is NULL.

--

You received this message because you are subscribed to the Google Groups 
"sqlalchemy" group.
To post to this group, send email to sqlalch...@googlegroups.com.
To unsubscribe from this group, send email to 
sqlalchemy+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/sqlalchemy?hl=en.


Reply via email to