Generation column operations include adding a STORED column, dropping a STORED column, adding a VIRTUAL column, and dropping a VIRTUAL column.
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);
The following example shows how to add a STORED column:
obclient> CREATE TABLE t1(c1 INT,c2 VARCHAR(50));
Query OK, 0 rows affected
obclient> ALTER TABLE t1 ADD COLUMN (c3 INT GENERATED ALWAYS AS (c1 + 1) STORED);
Query OK, 0 rows affected
Drop a STORED column
The syntax for dropping a STORED column is as follows:
ALTER TABLE table_name DROP COLUMN column_name;
The following example shows how to delete a STORED column:
obclient> ALTER TABLE t1 DROP COLUMN c3;
Query OK, 0 rows affected
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;
The following example shows how to add a VIRTUAL column:
obclient> ALTER TABLE t1 ADD COLUMN (c3 INT GENERATED ALWAYS AS (c1 + 1) VIRTUAL);
Query OK, 0 rows affected
Drop a VIRTUAL column
The syntax for dropping a VIRTUAL column is as follows:
ALTER TABLE table_name DROP COLUMN column_name;
The following example shows how to drop a VIRTUAL column:
obclient> ALTER TABLE t1 DROP COLUMN c3;
Query OK, 0 rows affected