sqlalchemy 不是 NULL 选择 [英] sqlalchemy IS NOT NULL select
问题描述
如何像在 SQL 中一样添加过滤器以从特定列中选择非 NULL 的值?
SELECT *发件人表你的列不为空的地方;
如何使用 SQLAlchemy 过滤器做同样的事情?
select = select(table).select_from(table).where(all_filters)
column_obj != None
将产生一个 IS NOT NULL
约束:
在列上下文中,生成子句 a != b
.如果目标是 None
,则生成 IS NOT NULL
.
或使用 isnot()
(0.7.9 新增):
实现 IS NOT
运算符.
通常,当与解析为 NULL
的 None
值进行比较时,会自动生成 IS NOT
.但是,如果与某些平台上的布尔值进行比较,可能需要显式使用 IS NOT
.
演示:
<预><代码>>>>从 sqlalchemy.sql 导入列>>>column('YourColumn') != None<sqlalchemy.sql.elements.BinaryExpression 对象在 0x10c8d8b90>>>>str(column('YourColumn') != None)'"YourColumn" 不是 NULL'>>>column('YourColumn').isnot(None)<sqlalchemy.sql.elements.BinaryExpression 对象在 0x104603850>>>>str(column('YourColumn').isnot(None))'"YourColumn" 不是 NULL'How can I add the filter as in SQL to select values that are NOT NULL from a certain column ?
SELECT *
FROM table
WHERE YourColumn IS NOT NULL;
How can I do the same with SQLAlchemy filters?
select = select(table).select_from(table).where(all_filters)
column_obj != None
will produce a IS NOT NULL
constraint:
In a column context, produces the clause
a != b
. If the target isNone
, produces aIS NOT NULL
.
or use isnot()
(new in 0.7.9):
Implement the
IS NOT
operator.Normally,
IS NOT
is generated automatically when comparing to a value ofNone
, which resolves toNULL
. However, explicit usage ofIS NOT
may be desirable if comparing to boolean values on certain platforms.
Demo:
>>> from sqlalchemy.sql import column
>>> column('YourColumn') != None
<sqlalchemy.sql.elements.BinaryExpression object at 0x10c8d8b90>
>>> str(column('YourColumn') != None)
'"YourColumn" IS NOT NULL'
>>> column('YourColumn').isnot(None)
<sqlalchemy.sql.elements.BinaryExpression object at 0x104603850>
>>> str(column('YourColumn').isnot(None))
'"YourColumn" IS NOT NULL'
这篇关于sqlalchemy 不是 NULL 选择的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!