PostgreSQL error code
PostgreSQL error 42710
42710 is the SQLSTATE PostgreSQL reports for duplicate object, in class 42, Syntax Error or Access Rule Violation.
| SQLSTATE | 42710 |
|---|---|
| Condition name | duplicate_object |
| Class | 42 — Syntax Error or Access Rule Violation |
Reproduce it, then fix it
Constraint names are unique per table, and both checks are called positive. Name each after what it checks. Run the broken query to see the error, then switch to the fixed one. Edit either freely; every run is rolled back.
ALTER TABLE products ADD CONSTRAINT positive CHECK (price > 0), ADD CONSTRAINT positive CHECK (stock_quantity >= 0);
ALTER TABLE products ADD CONSTRAINT price_positive CHECK (price > 0), ADD CONSTRAINT stock_not_negative CHECK (stock_quantity >= 0);