繁体   English   中英

sqlalchemy postgresql“为空”索引

[英]sqlalchemy postgresql “Is Null” index

如何在PostgreSQL上使用sqlalchemy创建IS NULL索引?

PostgreSQL 支持这个

索引列上的IS NULL或IS NOT NULL条件可以与B树索引一起使用。

我尝试了以下方法:

from flask_sqlalchemy import SQLAlchemy
db = SQLAlchemy()
class Foo(db.Model):
    id = Column(Integer, primary_key=True)
    processing_start_time = Column(DateTime, nullable=True)

    __table_args__ = (
        Index('processing_null_index', 'processing_start_time', is_null=True),
    )

我收到此错误:

/foo/venv/lib/python3.5/site-packages/sqlalchemy/sql/base.py:291: SAWarning: Can't validate argument 'is_null'; can't locate any SQLAlchemy dialect named 'is'
  (k, dialect_name))

IS NULL不是单独的索引类型。 在这种特定情况下, IS NULL部分索引上的条件表达式。 您可以通过postresql_where kwarg在SQLAlchemy中声明PostgreSQL的部分索引:

Index('processing_null_index', processing_start_time, postgresql_where=processing_start_time.is_(None))

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM