我正在使用 Elixir 和 sqla 0.6,我正在尝试查询我的模型:
class Document(Entity):
using_options(shortnames=True, order_by='doc_date')
doc_number = Field(Unicode(20),index=True)
...对于具有给定长度数字的文档。
我在想这样的事情:
Document.query.filter(Document.doc_number.char_lenght()==5).all()
...但显然,char_length 虽然存在于 sqlalchemy.sql.functions 中,但在这里不起作用。我怎样才能让它在声明性习语中工作,而不求助于直接查询?
最佳答案
好的,找到答案了:
from sqlalchemy import func
Document.query.filter(func.char_length(Document.doc_number)==5).all()
关于python - 使用sqlalchemy.sql.functions.char_length作为过滤条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6600008/