3156
MySQLERRORNotableJSONHIGH confidence

JSON_TABLE can only be used in the FROM clause

Production Risk

Low — syntax error; easy to fix.

What this means

JSON_TABLE() is a table-valued function that generates a virtual table and therefore can only appear in the FROM clause of a SELECT statement, not in SELECT expressions, WHERE, or other clauses.

Why it happens
  1. 1JSON_TABLE() used outside the FROM clause.
How to reproduce
trigger — this will error
trigger — this will error
SELECT JSON_TABLE('[]', '
#x27; COLUMNS(id INT PATH '$.id'));

expected output

ERROR 3156 (42000): JSON_TABLE can only be used in the FROM clause.

Fix

Move JSON_TABLE to the FROM clause

Move JSON_TABLE to the FROM clause
SELECT jt.id FROM JSON_TABLE('[]', '
#x27; COLUMNS(id INT PATH '$.id')) AS jt;

Why this works

JSON_TABLE must be in FROM to produce a relational result set.

What not to do

Sources
Official documentation ↗

MySQL 8.0 — 3156 ER_JSON_TABLE_NOT_IN_FROM

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All MySQL errors