表结构:v_date为虚拟列
CREATE TABLE `test` ( `json` TEXT NULL, `date` DATETIME NULL DEFAULT NULL, `v_date` DATE AS (json_extract(`json`,'$.date')) VIRTUAL)COMMENT='测试表\r\n'COLLATE='utf8mb4_general_ci'ENGINE=InnoDB;
插入:
INSERT INTO test (json) VALUES ('{"date":"2019-01-21 00:00:00"}');
报错:
ERROR 3156 (22018): Invalid JSON value for CAST to DATE/TIME/DATETIME/TIMESTAMP from column json_extract at row 1
尝试了各种格式:
INSERT INTO `test`.`test_virtual_column` (`json`) VALUES ('{"date":"20191221"}');/* SQL错误(3156):Invalid JSON value for CAST to DATE/TIME/DATETIME/TIMESTAMP from column json_extract at row 1 */INSERT INTO `test`.`test_virtual_column` (`json`) VALUES ('{"date":20191221}');/* SQL错误(3156):Invalid JSON value for CAST to DATE/TIME/DATETIME/TIMESTAMP from column json_extract at row 1 */
请问如何保存Date类型的数据到虚拟列中?
慕雪6442864
相关分类