PostgreSQL
 sql >> Base de Dados >  >> RDS >> PostgreSQL

Criando índice único parcial com sqlalchemy no Postgres

class ScheduledPayment(Base):
    id = Column(Integer, primary_key=True)
    invoice_id = Column(Integer)
    is_canceled = Column(Boolean, default=False)

    __table_args__ = (
        Index('only_one_active_invoice', invoice_id, is_canceled,
              unique=True,
              postgresql_where=(~is_canceled)),
    )