I want to make a tags
column of type json
:
e.g.,
id | tags
=========================================
1 | \'["tag1"
It's now possible with MySQL 8.0.17+
Something like this (not tested)
CREATE TABLE posts (
id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
tags JSON,
INDEX tags( (CAST(tags AS VARCHAR(32) ARRAY)) )
);
Use it this way:
SELECT * FROM posts
WHERE JSON_CONTAINS(tags, CAST('[tag1, tag2]' AS JSON));
More details and samples here: https://dev.mysql.com/doc/refman/8.0/en/json.html