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

wrong_object_type relation “…” is not a table — 42809

PostgreSQL error "relation "…" is not a table" (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 command that requires a table was applied to an object that is not a table (for example a view, sequence, or index). PostgreSQL raises SQLSTATE 42809 (wrong_object_type).

  • The named relation exists but is the wrong kind.
  • Common with table-only operations on a view/sequence.
  • The error identifies the object as not a table.

What the server log shows

ERROR:  "orders_view" is not a table

Why PostgreSQL raises this — what the manual says

As Chapter 5 Data Definition explains:

A command that requires an ordinary table was applied to a relation that is not a plain table — such as a view, index, sequence, composite type, or foreign table; use the command appropriate to the relation’s actual kind, or target a real table.

Many DDL/DML operations are valid only for ordinary tables. When the target relation is a different kind, PostgreSQL rejects the operation with 42809.

Common causes

  • Running a table-only command against a view or sequence.
  • A name collision between a table and another relation kind.
  • Targeting an index/materialized view where a table is required.

How to fix it

  1. Target the correct table, or use the command suited to the object kind.
  2. Check the object type: \d objectname in psql.
  3. Use ALTER VIEW/ALTER SEQUENCE for those object kinds.

Related & next steps

Reference: PostgreSQL 18 Chapter 5 “Data Definition”.

Was this helpful?