gpt4 book ai didi

python - 使用sqlalchemy.sql.functions.char_length作为过滤条件

转载 作者:太空狗 更新时间:2023-10-30 02:34:45 24 4
gpt4 key购买 nike

我正在使用 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com