Michael Bayer wrote:
> why dont you just stick with None instead of "nn" ? then you just
> write:
>
> if v is None:
> clause.append(self.c.field != v)
> else:
> clause.append(self.c.field == v)
It could be an idea but not intuitive and unnatural
because None = IS NOT NULL (very ugly) :-(
and null() = IS NULL
j
>
>
> On Mar 19, 2009, at 11:43 AM, jo wrote:
>
>
>> Well, MIchael, in my case a notnull() function could be very
>> interesting because
>> I'm using it in a function, and would like pass values as parameters
>> in such way:
>>
>>
>> def search( self, **kw ):
>> by_where_clause = []
>> for k,v in kw.items():
>> if k == 'myfield1':
>> if v == 'nn': # I use 'nn' to generate a NOT NULL
>> because we don't have a notnull() function
>> by_where_clause.append( self.c.field1 <> None)
>> else:
>> by_where_clause.append( self.c.field1 == v)
>>
>> elif k == 'myfield2':
>> if v == 'nn': # I use 'nn' to generate a NOT NULL
>> because we don't have a notnull() function
>> by_where_clause.append( self.c.field2 <> None)
>> else:
>> by_where_clause.append( self.c.field2 == v)
>>
>> elif k == 'myfield3':
>> if v == 'nn': # I use 'nn' to generate a NOT NULL
>> because we don't have a notnull() function
>> by_where_clause.append( self.c.field3 <> None)
>> else:
>> by_where_clause.append( self.c.field3 == v)
>> ...
>>
>>
>>
>>
>> Mytb.search(myfield=None) -- generates WHERE myfield IS NULL
>> Mytb.search(myfield=null()) -- generates WHERE myfield IS NULL
>> Mytb.search(myfield='nn') -- generates WHERE myfield IS NOT NULL
>>
>>
>>
>> if we have a notnull() function these thing could be easier:
>>
>> def search( self, **kw ):
>> by_where_clause = {}
>> for k,v in kw.items():
>> by_where_clause[ k ] = v
>>
>>
>> Mytb.search(myfield=None) -- generates WHERE myfield IS NULL
>> Mytb.search(myfield=null()) -- generates WHERE myfield IS NULL
>> Mytb.search(myfield=notnull()) -- generates WHERE myfield IS NOT NULL
>>
>> Michael Bayer wrote:
>>
>>> well usually null() and not_(null()) aren't needed as explicit
>>> constructs. comparisons like somecol == None and somecol != None
>>> will generate the appropriate NULL/NOT NULL expression.
>>>
>>>
>>> On Mar 19, 2009, at 4:48 AM, jo wrote:
>>>
>>>
>>>
>>>> Hi all,
>>>>
>>>> I would like to know if there's a notnull() function in sqlalchemy
>>>> similar to null()
>>>> to avoid things like not_(null()) ?
>>>>
>>>> thank you
>>>>
>>>> j
>>>>
>>>>
>>>>
>>>>
>>>
>>
>
>
> >
>
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---