Informix Error -546
-546 Cannot have host variables when creating a view view-name.
This statement either prepares or executes a CREATE VIEW statement in which the SELECT statement refers to host variables. This action is not supported. The SELECT statement in a view can be executed from any program and cannot rely on the variables of one program. Review the CREATE VIEW statement, and make sure that it does not contain the names of any host variables, an INTO clause, or a ? placeholder.
Database servers after Version 5.01 do not use this error message.
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-546 (which per the official guidance no longer occurs on database servers after Version 5.01,
though it remains documented for the codebases and platforms where it does) fires when a CREATE VIEW's underlying SELECT references a host variable, an INTO clause, or a ? placeholder —
none of which are meaningful in a view, since a view's SELECT must be runnable from any program,
not tied to one program's variables.
- A host variable referenced directly in the view's
SELECT(a:variable-style reference carried over from a program's embedded SQL), per the official guidance — the direct cause. - An
INTOclause included in the view'sSELECT, per the official guidance — meaningful in a standalone FETCH/SELECT, not in a view definition. - A
?placeholder left in the SELECT, per the official guidance, from code adapted out of a prepared/parameterized statement without removing the placeholder.
Solutions / Resolution
- Remove any host variable names from the
CREATE VIEWstatement'sSELECT, per the official guidance, replacing them with literal values or removing the dependency entirely. - Remove any
INTOclause, per the official guidance — a view's SELECT doesn't fetch into anything; it defines a queryable result set. - Remove any
?placeholder, per the official guidance, since a view can't be parameterized the way a prepared statement can.
Examples
The disallowed host-variable reference
CREATE VIEW recent_orders AS
SELECT * FROM orders WHERE order_date > :cutoff_date;
-- -546: :cutoff_date is a host variable, not valid in a view definition
Corrected — no host variable
CREATE VIEW recent_orders AS
SELECT * FROM orders WHERE order_date > TODAY - 30;
Diagnostic Checks
- Scan the view's
SELECTfor:variablereferences, anINTOclause, or a?placeholder — any of the three trigger this error.
Related Errors / Related Topics
No closely related error codes are cross-referenced for -546 in this set yet.
A view's SELECT must stand alone, usable from any program — remove host variables, INTO clauses,
and ? placeholders from the view definition.