Answer the question
In order to leave comments, you need to log in
How to remove a tuple from an array by the value of the tuple?
There is a following line in the table
+---+----------------------+
| id | sort
+---+----------------------+
| 1 | [12, 13, {"12": 123} ]
+---+----------------------+
How can I remove the element {"12": 123} without knowing its index in the array, but knowing the tuple itself ?
Answer the question
In order to leave comments, you need to log in
Divide into elements, discard unnecessary, collect back:
WITH cte AS (SELECT 1 id, CAST('[12, 13, {"12": 123} ]' AS JSON) sort)
SELECT cte.id, JSON_ARRAYAGG(jsontable.element) sort
FROM cte
CROSS JOIN JSON_TABLE(cte.sort,
'$[*]' COLUMNS (element JSON PATH '$')) jsontable
WHERE jsontable.element != CAST('{"12": 123}' AS JSON)
GROUP BY cte.id
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question