From DBeaver Community, I access my database and create a new SQL query. I write the corresponding code for the CTE I want to create, but it constantly shows a syntax error. I’ve tried everything, but I can’t find the error. If anyone can help me, it would be greatly appreciated. Thank you very much.
The Query I used is this:
— CTE Json
WITH json_extract AS (
SELECT
JSON_UNQUOTE(JSON_EXTRACT(`from`, '$.id')) AS from_id,
JSON_UNQUOTE(JSON_EXTRACT(`from`, '$.name')) AS from_name,
JSON_UNQUOTE(JSON_EXTRACT(`shares`, '$[0].count')) AS shares_count,
JSON_UNQUOTE(JSON_EXTRACT(`properties`, '$[0].text')) AS properties_length,
JSON_UNQUOTE(JSON_EXTRACT(`admin_creator`, '$.id')) AS admin_creator_id,
JSON_UNQUOTE(JSON_EXTRACT(`admin_creator`, '$.link')) AS admin_creator_link
FROM raw_post
)
SELECT *
FROM json_extract;
And the error I get is this one:
SQL Error [1064][42000]: You have an error in your SQL syntax; check
the manual that corresponds to your MySQL server version for the right
syntax to use near " at line 10
The dbms version I´m using is MySQL: 8.0.35
I need to extract each value from every column that has a json into a new column.
2
Answers
I don´t know what the problem was, but it actually worked yesterday using the same query. Maybe i typed something wrong without noticing, anyways! Thank you so much for your help!
I think you’re doing wrong something as no sample data available there.
I’m using
MySQL 8.0.35
in my local system and try your query with some dummy data. It’s working fine my end.According to you query there are atleast 4 columns in table:
raw_post
as follows:So, my sample data table:
raw_post
is:Output:
Working fine in
MySQL 8.3.0
Sample Code: MyCompiler
If your data type is OK then, it should not throw such error.