Sample Header Ad - 728x90

Postgres constraints: EXCLUDE (name WITH =) vs partial unique index

3 votes
1 answer
2110 views
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!
Asked by Andrew Polukhin (131 rep)
Jun 24, 2022, 09:28 AM
Last activity: Apr 12, 2024, 09:19 PM