3

I am refactoring my database constraint for such a table:

CREATE TABLE products (
  name text NOT NULL,
  status text NOT NULL
);

A former engineer working on the project had such a constraint:

ALTER TABLE products
  ADD CONSTRAINT unique_active_name
  EXCLUDE (name WITH =)
  WHERE (status = 'active' AND name <> '');

I am wondering if it is equivalent to such a partial unique index:

CREATE UNIQUE INDEX unique_active_name
  ON products(name)
  WHERE (status = 'active' AND name <> '');

I did not quite get the documentation for EXCLUDE, and would like to improve things. Thanks in advance!

1
  • 1
    Yes, both approaches are basically identically.
    – user1822
    Commented Jun 25, 2022 at 7:36

1 Answer 1

1

exclusionary constraints have indexes whose constraints are deferrable, whereas unique indexes do not

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.