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

标签 python sqlalchemy

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

相关文章:

python - sqlalchemy 中的并发

python - SqlAlchemy 检查关系属性是否在列表中

python - 使用 Python 进行 Excel win32com 编程。将参数传递给函数

python - 如何使用 Python 和 PIL 查找颜色相似的图像?

android - 如何在 Windows 上从 kivy 创建 .apk 文件

python - 将 JSON 发送到 Flask,request.args 与 request.form

python - 在 Sqlalchemy/Postgres 中使用绑定(bind)参数执行 WHERE IN

python - 将数据从 sqlalchemy 移动到 pandas DataFrame

python - 按日期列值的比例分布

python - 查询添加到 SQLAlchemy 中非提交 session 的对象