La versión 3.7 de MySQL por fin permite definir columnas de tipo JSON (como ya hacían Postgresql u Oracle):
El tipo de datos se define así:
ALTER TABLE people ADD COLUMN (tags json);
Se puede consultar:
SELECT name, tags FROM people LIMIT 5;
Y nos devuelve:
Permite también trabajar de forma sencilla con arrays, JSON_SET(), JSON_ARRAY_APPEND() y JSON_SEARCH():
SELECT name, tags from people WHERE JSON_SEARCH(tags, 'one', 'Lorem') IS NOT NULL;
O
UPDATE people SET profile = JSON_SET(profile, "$.first_aid", true) WHERE id = 3;
O
SELECT name, profile->"$.direct_reports" reports, profile->"$.salary" salary FROM people WHERE profile->"$.direct_reports" >= 10;


Deja un comentario