PostgreSQL error code
PostgreSQL error 42P16
42P16 is the SQLSTATE PostgreSQL reports for invalid table definition, in class 42, Syntax Error or Access Rule Violation.
| SQLSTATE | 42P16 |
|---|---|
| Condition name | invalid_table_definition |
| Class | 42 — Syntax Error or Access Rule Violation |
Reproduce it, then fix it
products already has a primary key, and a table can only have one. To keep another column unique, add a UNIQUE constraint. 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 PRIMARY KEY (name);
ALTER TABLE products ADD UNIQUE (name);