2

I have table schema as:

table_a:
    id
    active boolean
 
table_b:
    id
    table_a_id ForeignKey

I want to apply a partial unique index on table_b but only if active=True for table_a_id.

Is this feasible in postgres?

1
  • 3
    I don't think that you want to create an index on another table will be worked. Commented Mar 11, 2022 at 10:05

1 Answer 1

5

Not possible. From the 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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.