cannot insert into view “…”
Symptoms
An INSERT targeted a view that is not automatically updatable and has no INSTEAD OF trigger or rule. PostgreSQL raises SQLSTATE 0A000 (feature_not_supported).
- Inserting into a non-updatable view.
- No INSTEAD OF trigger or DO INSTEAD rule defined.
- The HINT suggests how to make it work.
What the server log shows
ERROR: cannot insert into view "order_summary"
DETAIL: Views containing GROUP BY are not automatically updatable.
HINT: To enable inserting into the view, provide an INSTEAD OF INSERT trigger or an unconditional ON INSERT DO INSTEAD rule.
Why PostgreSQL raises this — what the manual says
the CREATE VIEW reference (Updatable Views):
“A more complex view that does not satisfy all these conditions is read-only by default: the system will not allow an INSERT, UPDATE, DELETE, or MERGE on the view.”
PostgreSQL can auto-translate writes only for simple views. A view using aggregation, DISTINCT, GROUP BY, joins, etc. has no unambiguous mapping back to base rows, so without an INSTEAD OF trigger/rule the write is unsupported (0A000).
Common causes
- Writing to a view with GROUP BY/DISTINCT/aggregates/joins.
- No INSTEAD OF trigger or DO INSTEAD rule on the view.
- Assuming all views are writable.
How to fix it
- Add an
INSTEAD OF INSERTtrigger that writes to base tables. - Define an unconditional
ON INSERT DO INSTEADrule. - Insert directly into the underlying base table.
Related & next steps
Reference: PostgreSQL 18 — CREATE VIEW.