SQLSTATE 42809 ERROR Class 42: Syntax Error or Access Rule Violation

wrong_object_type “…” is not a view — 42809

PostgreSQL error ""…" is not a view" (SQLSTATE 42809): what it means, common causes, and how to fix it.

PG 12, 13, 14, 15, 16, 17, 18 Official docs
Last reviewed May 2025 Grounded in source

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 VIEW over 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 VIEW on a non-view object.

How to fix it

  1. Use a different view name, or drop the conflicting object first.
  2. Use ALTER TABLE for tables and ALTER VIEW for views.
  3. Check the object type with \d orders.

Related & next steps

Reference: PostgreSQL 18 — CREATE VIEW.

Was this helpful?