# any custom operator
select([users.c.user_name.op('||')('_category')])
+ # "null" comparison via == (converts to IS)
+ {sql}users.select(users.c.user_name==None).execute()
+ SELECT users.user_id, users.user_name, users.password
+ FROM users
+ WHERE users.user_name IS NULL
+
+ # or via explicit null() construct
+ {sql}users.select(users.c.user_name==null()).execute()
+ SELECT users.user_id, users.user_name, users.password
+ FROM users
+ WHERE users.user_name IS NULL
+
#### Specifying the Engine {@name=engine}
For queries that don't contain any tables, the SQLEngine can be specified to any constructed statement via the `engine` keyword parameter:
def _bind_param(self, obj):
return BindParamClause('literal', obj, shortname=None, type=self.type)
def _compare(self, operator, obj):
- if _is_literal(obj):
- if obj is None:
- if operator == '=':
- return BooleanExpression(self._compare_self(), null(), 'IS')
- elif operator == '!=':
- return BooleanExpression(self._compare_self(), null(), 'IS NOT')
- else:
- raise exceptions.ArgumentError("Only '='/'!=' operators can be used with NULL")
+ if obj is None or isinstance(obj, Null):
+ if operator == '=':
+ return BooleanExpression(self._compare_self(), null(), 'IS')
+ elif operator == '!=':
+ return BooleanExpression(self._compare_self(), null(), 'IS NOT')
return BooleanExpression(self._compare_self(), null(), 'IS')
else:
- obj = self._bind_param(obj)
+ raise exceptions.ArgumentError("Only '='/'!=' operators can be used with NULL")
+ elif _is_literal(obj):
+ obj = self._bind_param(obj)
return BooleanExpression(self._compare_self(), obj, operator, type=self._compare_type(obj))
def _operate(self, operator, obj):
if _is_literal(obj):