0

PostgreSQL exclusion constraints are documented briefly under

But, the syntax for ALTER TABLE does not mention /EXCLUDE/ anywhere. How do I add one if one is not already present.

I can in psql, TAB-complete

ALTER TABLE foo ADD

However subsequent tabs do not provide CONSTRAINT which the documentation mentions nor anything that comes after.

1 Answer 1

3

Follow the example here by ypercube

ALTER TABLE table_name
  ADD CONSTRAINT only_one_is_active_value_per_name
    EXCLUDE  USING gist
    ( name WITH =, 
      is_active WITH <> 
    );

The ALTER TABLE command only lists examples of constraints. Constraints are actually added with the same syntax on DDL-Constraints,

CREATE TABLE foo (
  -- stuff
  EXCLUDE USING gist ( name WITH =, is_active WITH <> );
);

ALTER TABLE foo
  ADD CONSTRAINT
  EXCLUDE USING gist ( name WITH =, is_active WITH <> );

Your Answer

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

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