gpt4 book ai didi

python - 如何使用 SQLalchemy 执行 "starts with"查询?

转载 作者:太空狗 更新时间:2023-10-29 17:37:02 25 4
gpt4 key购买 nike

我正在学习使用 SQL Alchemy 连接到 mysql 数据库。我想从数据库中提取以给定字符串开头的记录。我知道对于简单的平等,我需要做的就是这个

queryRes = ses.query(Table).filter(Table.fullFilePath == filePath).all()
result = []

我该如何做这样的事情?

queryRes = ses.query(Table).filter(Table.fullFilePath.startsWith(filePath)).all()
result = []

也许查询看起来像这样?

q = ses.query(Table).filter(Table.fullFilePath.like('path%')).all()

最佳答案

SQLAlchemy 有一个 startswith column property ,所以它的工作原理与您想象的完全一样:

queryRes = ses.query(Table).filter(Table.fullFilePath.startswith(filePath)).all()

关于python - 如何使用 SQLalchemy 执行 "starts with"查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20269260/

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