【问题标题】:SQLAlchemy fast searchSQLAlchemy 快速搜索
【发布时间】:2018-10-10 20:14:13
【问题描述】:

我将烧瓶与 SQLAlchemy、SQLAlchemy-Searchable 和 PostgreSQL(表中的 3m 行)一起使用。 count() 函数非常慢,所以我想使用 count_estimate() (https://wiki.postgresql.org/wiki/Count_estimate)

q = Article.query.search(query,sort=True)
answers = q.limit(5).all()

如何将 SQLAlchemy 的查询与原始 sql 连接起来?谢谢。

【问题讨论】:

    标签: python flask sqlalchemy


    【解决方案1】:

    您可以使用 func.count() 函数来做到这一点。

    select([func.count()]).select_from(table)
    

    否则,用于在查询部分运行原始 sql。你可以使用 text() 函数。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-03-20
      • 2021-01-24
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多