sql >> Base de Datos >  >> RDS >> Mysql

¿Cómo extraer filas de una matriz json usando mysql udf json_extract 0.4.0?

Tu sintaxis dentro de json_extract() estaba un poco apagado. Intenta usar esto en su lugar:

SET @mapJSON = '[{"from":12,"to":0},{"from":11,"to":-1},{"from":1,"to":1}]' ;
SELECT JSON_EXTRACT(@mapJSON, "$.from") AS `from`,
       JSON_EXTRACT(@mapJSON, "$.to") AS `to`

Esto debería darte un conjunto de resultados parecido a este:

from         to
[12, 11, 1]  [0, -1, 1]