I'm working with JSON tables and I'm running into an issue. I get the following error:
Error Code: 1210. Incorrect arguments to JSON_TABLE
I'm using MySQL Engine version 8.0.20 on AWS with MySQL Workbench
When I use the JSON_Table command directly off of my table (sf.purchases), I am able to get the expected JSON output. For instance this works:
SELECT pur.*, jt.*
FROM sf.purchases AS pur,
JSON_TABLE (pur.items, '$[*]'
COLUMNS (
C_jt_id FOR ORDINALITY,
C_jt_item_uid VARCHAR(255) PATH '$.item_uid',
C_jt_item_name VARCHAR(255) PATH '$.name',
C_jt_qty INT PATH '$.qty',
C_jt_price DOUBLE PATH '$.price')
) AS jt;
An it converts '[{"qty": "1", "name": "Test", "price": "59.99", "item_uid": "320-000002"}]'
into its respective columns.
However, when I create a VIEW I can't get JSON_TABLE to work on the resulting table
Here is the VIEW I create:
CREATE VIEW sf.lp AS
(SELECT * FROM sf.purchases);
Here is the code that does NOT work
SELECT pur.*, jt.*
FROM sf.lp AS pur,
JSON_TABLE (pur.items, '$[*]'
COLUMNS (
C_jt_id FOR ORDINALITY,
C_jt_item_uid VARCHAR(255) PATH '$.item_uid',
C_jt_item_name VARCHAR(255) PATH '$.name',
C_jt_qty INT PATH '$.qty',
C_jt_price DOUBLE PATH '$.price')
) AS jt;
The RESPONSE is: Error Code: 1210. Incorrect arguments to JSON_TABLE
I've checked the following:
- I've reduced the COLUMNs to see if that affects anything
- I've checked the dataset to see if any weird characters were somehow introduced
- The two tables and the Columns and Datatypes are identical. Most importantly,
itemsis of type JSON if both the TABLE (sf.purchases) and the VIEW (sf.lp) - Both the TABLE and VIEW use Character Set latin 1 and Collation latin1-swedish_ci
- I've run JSON_STORAGE_SIZE to verify that items in the table adhere to the JSON format
SELECT pur.items,
JSON_STORAGE_SIZE(pur.items)
FROM sf.lp pur
Any ideas or help would be appreciated.