Informix Error -504
Cause and resolution
Cannot lock a view.
This LOCK TABLE statement cannot be carried out because the table specified is really a view. Only real tables can be locked. Roll back the current transaction. Then redesign the operation to work against the real tables on which the view is based, or open the database in exclusive mode.
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-504 fires when a LOCK TABLE statement names a view rather than a real, storage-backed table —
views have no rows of their own to lock, so the operation is rejected outright.
LOCK TABLE viewnameissued directly against a view, per the official guidance — the direct, only cause.- Generated or templated SQL that locks tables by name from a list, where the list wasn't filtered to exclude views before the lock statements were built.
- Confusion between a view and the base table it's built on, especially when both share a similar or identical name in different naming conventions.
Solutions / Resolution
- Roll back the current transaction, per the official guidance.
- Redesign the operation to work against the view's underlying real tables, per the official
guidance, locking those directly instead:
LOCK TABLE base_table_name IN EXCLUSIVE MODE; - Or open the database in exclusive mode, per the official guidance, if the operation needs broader protection than locking the specific base tables provides.
- Confirm which underlying tables a view depends on before writing the lock statements, so the correct base-table names are used from the start.
Examples
The disallowed attempt
LOCK TABLE active_orders_view IN SHARE MODE;
-- -504: Cannot lock a view.
Locking the real table instead
LOCK TABLE orders IN SHARE MODE;
Diagnostic Checks
- Query
sysviews/systablesto confirm whether a name refers to a view or a base table before issuing aLOCK TABLEstatement against it:SELECT tabname, tabtype FROM systables WHERE tabname = 'active_orders_view';tabtype = 'V'indicates a view.
Related Errors / Related Topics
No closely related error codes are cross-referenced for -504 in this set yet.
Views can't be locked directly — lock the base table(s) the view is built on instead.