条件分开的 Postgres 部分索引 table

Partial Index on Postgres where condition is in separate table

我有 table 架构为:

table_a:
    id
    active boolean
 
table_b:
    id
    table_a_id ForeignKey

我想在 table_b 上应用部分唯一索引,但前提是 table_a_id.

的 active=True

这在 postgres 中可行吗?

不可能。来自 manual:

The expression used in the WHERE clause can refer only to columns of the underlying table, but it can use all columns, not just the ones being indexed.