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