PostgreSQL error code
PostgreSQL error 42P07
42P07 is the SQLSTATE PostgreSQL reports for duplicate table, in class 42, Syntax Error or Access Rule Violation.
| SQLSTATE | 42P07 |
|---|---|
| Condition name | duplicate_table |
| Class | 42 — Syntax Error or Access Rule Violation |
Reproduce it, then fix it
A table, view, index or sequence with that name already exists in the schema; they all share one namespace. Use IF NOT EXISTS, or pick another name. Run the broken query to see the error, then switch to the fixed one. Edit either freely; every run is rolled back.
CREATE TABLE products (id int PRIMARY KEY, name text);
CREATE TABLE IF NOT EXISTS products (id int PRIMARY KEY, name text);