PostgreSQL error code
PostgreSQL error 42701
42701 is the SQLSTATE PostgreSQL reports for duplicate column, in class 42, Syntax Error or Access Rule Violation.
| SQLSTATE | 42701 |
|---|---|
| Condition name | duplicate_column |
| Class | 42 — Syntax Error or Access Rule Violation |
Reproduce it, then fix it
SELECT * over a join returns both tables’ id columns, and a table can’t have two columns with the same name. List the columns, and rename the ones that clash. Run the broken query to see the error, then switch to the fixed one. Edit either freely; every run is rolled back.
CREATE TABLE order_report AS SELECT * FROM orders o JOIN customers c ON c.id = o.customer_id;
CREATE TABLE order_report AS SELECT o.id AS order_id, c.id AS customer_id, c.email, o.total_amount FROM orders o JOIN customers c ON c.id = o.customer_id; SELECT * FROM order_report LIMIT 3;