GBase 8a database cluster currently does not support field definition modification. Except for the varchar type, the length can be increased, other types or attributes are not allowed. You need to rebuild a field for transition.
Refer to http://www.gbase8.cn/1357
Varchar type increases the length
Be sure to keep the original additional attributes, including not null, default, etc. Otherwise, an error will be reported when changing. To modify the comments individually, please use the modify function.
gbase> desc t2;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | varchar(20) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
2 rows in set (Elapsed: 00:00:00.00)
gbase> alter table t2 change name name varchar(30);
Query OK, 0 rows affected, 1 warning (Elapsed: 00:00:00.98)
Records: 0 Duplicates: 0 Warnings: 0
gbase> desc t2;
+-------+-------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+-------------+------+-----+---------+-------+
| id | int(11) | YES | | NULL | |
| name | varchar(30) | YES | | NULL | |
+-------+-------------+------+-----+---------+-------+
2 rows in set (Elapsed: 00:00:00.00)
gbase>
Other types of changes
Other types only have to create a new field first, then update the data, then delete the old one, and change the new one to the old field name.
In the following example, change value bigint, to value int.
gbase> desc t1;
+-------+------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+------------+------+-----+---------+-------+
| id | int(11) | YES | MUL | NULL | |
| value | bigint(20) | YES | | NULL | |
| birth | datetime | YES | | NULL | |
+-------+------------+------+-----+---------+-------+
3 rows in set (Elapsed: 00:00:00.00)
gbase> alter table t1 add column value2 int after value;
Query OK, 4 rows affected (Elapsed: 00:00:00.65)
Records: 4 Duplicates: 4 Warnings: 0
gbase> desc t1;
+--------+------------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+------------+------+-----+---------+-------+
| id | int(11) | YES | MUL | NULL | |
| value | bigint(20) | YES | | NULL | |
| value2 | int(11) | YES | | NULL | |
| birth | datetime | YES | | NULL | |
+--------+------------+------+-----+---------+-------+
4 rows in set (Elapsed: 00:00:00.00)
gbase> update t1 set value2=value;
Query OK, 4 rows affected (Elapsed: 00:00:00.28)
Rows matched: 4 Changed: 4 Warnings: 0
gbase> alter table t1 drop value;
Query OK, 4 rows affected (Elapsed: 00:00:00.42)
Records: 4 Duplicates: 4 Warnings: 0
gbase> desc t1;
+--------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+--------+----------+------+-----+---------+-------+
| id | int(11) | YES | MUL | NULL | |
| value2 | int(11) | YES | | NULL | |
| birth | datetime | YES | | NULL | |
+--------+----------+------+-----+---------+-------+
3 rows in set (Elapsed: 00:00:00.00)
gbase> alter table t1 change value2 value int;
Query OK, 0 rows affected (Elapsed: 00:00:00.21)
Records: 0 Duplicates: 0 Warnings: 0
gbase> desc t1;
+-------+----------+------+-----+---------+-------+
| Field | Type | Null | Key | Default | Extra |
+-------+----------+------+-----+---------+-------+
| id | int(11) | YES | MUL | NULL | |
| value | int(11) | YES | | NULL | |
| birth | datetime | YES | | NULL | |
+-------+----------+------+-----+---------+-------+
3 rows in set (Elapsed: 00:00:00.01)