3612
MySQLERRORNotableQueryHIGH confidence
Table function cannot be used over a UNION
Production Risk
Medium — Query fails; JSON processing pipelines may be disrupted.
How to reproduce
trigger — this will error
trigger — this will error
SELECT * FROM JSON_TABLE('[1,2]', '$[*]' COLUMNS (v INT PATH '#x27;)) jt
UNION
SELECT * FROM JSON_TABLE('[3,4]', '$[*]' COLUMNS (v INT PATH '#x27;)) jt2;expected output
ERROR 3612 (HY000): Table function cannot be resolved over a UNION.
Fix
Use subqueries with UNION
Use subqueries with UNION
SELECT v FROM (SELECT * FROM JSON_TABLE('[1,2]', '$[*]' COLUMNS (v INT PATH '#x27;)) jt) sub1
UNION ALL
SELECT v FROM (SELECT * FROM JSON_TABLE('[3,4]', '$[*]' COLUMNS (v INT PATH '#x27;)) jt2) sub2;Why this works
Wraps each table function in a derived table before the UNION.
What not to do
✕
Version notes
Sources
Official documentation ↗
MySQL 8.0 — 3612 ER_UNRESOLVED_TABLE_FUNCTION_OVER_UNION
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev