Support for Virtually Generated Columns

TheColorRed's profile image TheColorRed posted 8 years ago in Feature discussion Permalink

In mysql you can have virtually generated columns, which can be built off of a JSON type. So creating a table with these columns would be nice.

Take this CREATE TABLE query:

CREATE TABLE `client` (
    `client_id` INT(10) UNSIGNED NOT NULL AUTO_INCREMENT,
    `user_id` INT(10) UNSIGNED NOT NULL,
    `info` JSON NOT NULL,
    `browser` VARCHAR(50) generated always as (info->'$.browser'),
    `platform` VARCHAR(50) generated always as (info->'$.platform'),
    `is_mobile` VARCHAR(50) generated always as (info->'$.ismobiledevice'),
    `is_tablet` VARCHAR(50) generated always as (info->'$.istablet'),
    `date` TIMESTAMP NOT NULL DEFAULT CURRENT_TIMESTAMP,
    PRIMARY KEY (`client_id`),
    INDEX `user_id` (`user_id`)
);

With this json:

{
    "browser": "Chrome",
    "platform": "Win64",
    "ismobiledevice": false,
    "istablet": false
}

When inserted into the table mysql will take the specified columns and get the data from the json string.

Here is some more information: https://dev.mysql.com/doc/refman/5.7/en/create-table-secondary-indexes.html

Please login to leave a reply, or register at first.