Skip to main content

Generated column operations

The generated column operations in seekdb include adding, modifying, and dropping STORED columns and adding and dropping VIRTUAL columns.

Add a STORED column

The syntax for adding a STORED column is as follows:

ALTER TABLE table_name ADD COLUMN (column_name INT GENERATED ALWAYS AS
(column_expression) STORED);

Here is an example of adding a STORED column:

CREATE TABLE t1(c1 INT,c2 VARCHAR(50));
Query OK, 0 rows affected (0.002 sec)

ALTER TABLE t1 ADD COLUMN (c3 INT GENERATED ALWAYS AS (c1 + 1) STORED);
Query OK, 0 rows affected (0.063 sec)

Drop a STORED column

The syntax for dropping a STORED column is as follows:

ALTER TABLE table_name DROP COLUMN column_name;

Here is an example of dropping a STORED column:

ALTER TABLE t1 DROP COLUMN c3;
Query OK, 0 rows affected (0.002 sec)

Add a VIRTUAL column

The syntax for adding a VIRTUAL column is as follows:

ALTER TABLE table_name ADD COLUMN column_name INT GENERATED ALWAYS AS
(column_expression) VIRTUAL;

Here is an example of adding a VIRTUAL column:

ALTER TABLE t1 ADD COLUMN (c3 INT GENERATED ALWAYS AS (c1 + 1) VIRTUAL);
Query OK, 0 rows affected (0.013 sec)

Drop a VIRTUAL column

The syntax for dropping a VIRTUAL column is as follows:

ALTER TABLE table_name DROP COLUMN column_name;

Here is an example of dropping a VIRTUAL column:

ALTER TABLE t1 DROP COLUMN c3;
Query OK, 0 rows affected (0.006 sec)