Informix Error -322
-322 Cannot Alter view, Rename view or Create a trigger on a view.
Starting with version 9.40, you can only create an INSTEAD OF trigger on a view. You cannot create an INSTEAD OF trigger on a view created using WITH CHECK OPTION.
Consider creating the trigger on the base table of the view or create a table with the same schema as the view and then define the trigger on the table.
You can also receive this message if you issue the START VIOLATIONS TABLE statement or the STOP VIOLATIONS TABLE statement for a view. You must specify the name of a base table in both of these statements.
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-322 covers a cluster of view restrictions: views can't be altered or renamed like base tables, and (with a narrow exception) can't have triggers created on them either.
- Attempting
ALTER TABLEorRENAME TABLE-style structural operations against a view — views aren't modifiable this way; they'd need to be dropped and recreated with a new definition instead. - Attempting
CREATE TRIGGERon a view without usingINSTEAD OF— as of version 9.40, onlyINSTEAD OFtriggers are supported on views, and not even those on views createdWITH CHECK OPTION. - Attempting
START VIOLATIONS TABLE/STOP VIOLATIONS TABLEagainst a view — these statements require a base table, not a view. - A view created
WITH CHECK OPTION, where even theINSTEAD OFtrigger exception doesn't apply.
Solutions / Resolution
- To change a view's structure, drop and recreate it with the new definition, rather than
attempting
ALTER/RENAME. - To add trigger logic to a view, use
CREATE TRIGGER ... INSTEAD OF(9.40+) — this only works if the view wasn't createdWITH CHECK OPTION. - If
WITH CHECK OPTIONis required and trigger logic is also needed, put the trigger on the underlying base table instead, or define a new plain table with the same schema and put the trigger there. - For violations tables, target the underlying base table, not the view.
Examples
Attempting to alter a view directly
ALTER VIEW customer_orders ADD (region VARCHAR(20));
-- -322: views can't be altered this way
Fix — drop and recreate with the new definition:
DROP VIEW customer_orders;
CREATE VIEW customer_orders AS
SELECT c.customer_id, c.name, o.order_id, o.total, c.region
FROM customers c, orders o
WHERE c.customer_id = o.customer_id;
Creating an INSTEAD OF trigger instead of a regular one
CREATE TRIGGER customer_orders_upd UPDATE ON customer_orders ...;
-- -322: a regular trigger isn't allowed on a view
CREATE TRIGGER customer_orders_upd INSTEAD OF UPDATE ON customer_orders
REFERENCING NEW AS new OLD AS old
FOR EACH ROW (
UPDATE orders SET total = new.total WHERE order_id = old.order_id
);
Diagnostic Checks
- Confirm whether the target is a view or a base table (
systables.tabtype) before attemptingALTER/RENAME/CREATE TRIGGER/violations-table statements. - Check whether the view was created
WITH CHECK OPTIONif anINSTEAD OFtrigger attempt still fails.
Related Errors / Related Topics
- -302 — "No GRANT option or illegal option on multi-table view." Another view-specific restriction in the same general "views aren't base tables" family.
Views can't be altered/renamed and only support INSTEAD OF triggers (and not even those with
WITH CHECK OPTION) — restructure by dropping and recreating, or move the logic to the
underlying base table.