Search code examples
mysqldata-virtualization

How to get virtual expression in mysql?


I have a table with a virtual field like this one:

CREATE TABLE `deleteme` (
    `number` int(11),
    `result` int(11) GENERATED ALWAYS AS (`number` + 1) STORED
)

How to get the expression from virtual field result?

`number` + 1

I would like avoid using SHOW CREATE TABLE to search for the string.


Solution

  • You could query metadata tables:

    SELECT column_name, generation_expression
    FROM INFORMATION_SCHEMA.COLUMNS
    WHERE TABLE_NAME = 'deleteme';
    

    db<>fiddle demo