i have this table:
CREATE TABLE `datacollector` (
`id` binary(16) NOT NULL,
`created_at` timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP,
`processed` char(1) COLLATE utf8mb4_unicode_ci NOT NULL DEFAULT 'N',
`processed_at` timestamp NULL DEFAULT NULL,
`request` json NOT NULL,
`response` json NOT NULL,
`response_date` timestamp GENERATED ALWAYS AS (from_unixtime(json_unquote(json_extract(`response`,_utf8mb4'$.date')))) VIRTUAL NULL,
`sha224` varchar(80) COLLATE utf8mb4_unicode_ci NOT NULL,
`available_for` json NOT NULL,
PRIMARY KEY (`id`),
UNIQUE KEY `uniq_sha224` (`sha224`),
KEY `created_at` (`created_at`) /*!80000 INVISIBLE */,
KEY `cmoa` (`created_at`,`processed`) /*!80000 INVISIBLE */,
KEY `response_date` (`response_date`) /*!80000 INVISIBLE */
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci
I use a trigger that creates an array of strings in available_for. Now i would like to create a Index for available_for.
I tried already
ALTER TABLE `hwtools`.`datacollector`
ADD INDEX `available_for_idx` ((CAST(json_unquote(available_for) AS UNSIGNED ARRAY)));
or
ALTER TABLE `hwtools`.`datacollector`
ADD INDEX `available_for_idx` ((CAST(available_for AS UNSIGNED ARRAY)));
which give me always an error.
The JSON that is stored in available_for looks like '["getUserInfo", "stashClient"]'.
How can i create now with the last MySQL 8 a correct index?
Thank you for your Input on my problem.
13:21:41 ALTER TABLE hwtools.datacollector ADD INDEX available_for_idx ((CAST(available_for AS VARCHAR(32) ARRAY))) VISIBLE Error Code: 1064. 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 'VARCHAR(32) ARRAY))) VISIBLE' at line 2 0.031 sec14:39:00 ALTER TABLE hwtools.datacollector ADD INDEX available_for_idx ((CAST(available_for AS CHAR ARRAY))) VISIBLE Error Code: 1235. This version of MySQL doesn't yet support 'CAST-ing data to array of char/binary BLOBs' 0.031 sec