Informix Error -522: Table table-name not selected in query.
Cause and resolution
Table table-name not selected in query.
You used a correlation name to qualify a column name in either a GROUP BY clause or a SET clause. Consider rewriting the statement in an SPL routine that you then use as the triggered action, passing the column value as an argument. In any case, you must rewrite the statement without a using a correlation name in the GROUP BY clause or the SET clause.
Oninit® Troubleshooting Guidance
Reasons / Common Causes
-522 fires when a correlation name (table alias) is used to qualify a column in a GROUP BY
clause or a trigger's SET clause — those clauses specifically don't accept correlation-name
qualification, per the official guidance.
- A correlation name used to qualify a
GROUP BYcolumn — the column reference itself may be valid, but qualifying it with the query's table alias isn't accepted in that clause. - A trigger's
SETclause referencing a column through a correlation name (for instance, theNEW/OLDcorrelation names in an SPL trigger action), where the official guidance points specifically at rewriting the triggered action as an SPL routine instead. - Copy-pasted SQL from a
SELECT's column list, where correlation-qualified references are normal, into aGROUP BYorSETclause where they aren't accepted.
Solutions / Resolution
- Rewrite the statement without a correlation name in the
GROUP BYclause or theSETclause, per the official guidance — this is required in every case, not just a suggestion. - For a trigger's triggered action needing correlation-qualified values, per the official guidance, consider rewriting it as an SPL routine invoked as the triggered action, passing the column value as an argument instead of qualifying it inline.
Examples
The disallowed qualification in GROUP BY
SELECT o.status, COUNT(*) FROM orders o GROUP BY o.status;
-- -522: correlation name 'o' not accepted qualifying a GROUP BY column
Corrected — no correlation qualifier in GROUP BY
SELECT o.status, COUNT(*) FROM orders o GROUP BY status;
A trigger SET clause, rewritten as an SPL routine
-- Instead of qualifying a correlation name directly in the triggered SET clause,
-- call an SPL routine as the triggered action, passing the value as an argument:
CREATE TRIGGER trg_orders_update UPDATE OF status ON orders
REFERENCING NEW AS post FOR EACH ROW
(EXECUTE PROCEDURE log_status_change(post.status));
Diagnostic Checks
- Scan
GROUP BYand triggerSETclauses for correlation-name-qualified columns, since those are the two contexts this restriction applies to.
Related Errors / Related Topics
No closely related error codes are cross-referenced for -522 in this set yet.
Correlation names aren't accepted in GROUP BY or trigger SET clauses — drop the qualifier, or
for triggers, move the logic into an SPL routine passed the value as an argument.