Seaquel
PostgreSQL error code

PostgreSQL error 42809

42809 is the SQLSTATE PostgreSQL reports for wrong object type, in class 42, Syntax Error or Access Rule Violation.

SQLSTATE42809
Condition namewrong_object_type
Class42 — Syntax Error or Access Rule Violation

Reproduce it, then fix it

A plain view stores no rows, so there’s nothing to index. Index the table the view reads from, with the view’s filter as a partial index if it helps. Run the broken query to see the error, then switch to the fixed one. Edit either freely; every run is rolled back.

CREATE VIEW us_customers AS SELECT * FROM customers WHERE country = 'US';
CREATE INDEX ON us_customers (email);
CREATE VIEW us_customers AS SELECT * FROM customers WHERE country = 'US';
CREATE INDEX ON customers (email) WHERE country = 'US';
SELECT email FROM us_customers;

Source: PostgreSQL documentation, Appendix A