Diagnostic Queries
Symptoms
A view-specific command (such as CREATE OR REPLACE VIEW or ALTER VIEW) targeted an object that is not a view. PostgreSQL raises SQLSTATE 42809 (wrong_object_type).
- The object exists but is a table, not a view.
- Common with
CREATE OR REPLACE VIEWover an existing table name. - The error names the conflicting object.
What the server log shows
ERROR: "orders" is not a view
Why PostgreSQL raises this — what the manual says
As the CREATE VIEW reference (Notes) explains:
A command that expects a view (such as ALTER VIEW or CREATE OR REPLACE VIEW) was applied to a relation that is not a view — it is a table, sequence, materialized view, or other relation type; use the DROP/ALTER command appropriate to the relation’s actual kind.
View commands require the target to be a view. When the name resolves to a table or another relation kind, PostgreSQL cannot apply the view operation and reports 42809.
Common causes
- A table and view name collision.
- Trying to replace a table using
CREATE OR REPLACE VIEW. - Running
ALTER VIEWon a non-view object.
How to fix it
- Use a different view name, or drop the conflicting object first.
- Use
ALTER TABLEfor tables andALTER VIEWfor views. - Check the object type with
\d orders.
Related & next steps
Reference: PostgreSQL 18 — CREATE VIEW.
Thanks — noted. This helps keep the database accurate.