xstore表修改表结构和行存表语法一致,使用ALTER TABLE 语句对指定表进行操作:
ALTER TABLE table_name <action>;
其中,<action> 操作包括:增加字段,删除字段,修改字段名,修改表名等。
增加字段
xstore表增加字段和行存表语法一致,使用ADD COLUMN 语句增加字段。
teledb=# alter table xt add column c1 int;
ALTER TABLE
teledb=# teledb=# \d+ xt;
Table "public.xt"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
--------+---------+-----------+----------+---------+----------+--------------+-------------
a | integer | | not null | | plain | |
b | integer | | | | plain | |
c | text | | | | extended | |
c1 | integer | | | | plain | |
Indexes:
"xt_pkey" PRIMARY KEY, xbtree (a)
Distribute By: HASH(a)
Location Nodes: ALL DATANODES
删除字段
xstore表删除字段和行存表语法一致,使用DROP COLUMN 语句删除字段。
teledb=# alter table xt drop column c1;
ALTER TABLE
teledb=# \d+ xt;
Table "public.xt"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
--------+---------+-----------+----------+---------+----------+--------------+-------------
a | integer | | not null | | plain | |
b | integer | | | | plain | |
c | text | | | | extended | |
Indexes:
"xt_pkey" PRIMARY KEY, xbtree (a)
Distribute By: HASH(a)
Location Nodes: ALL DATANODES
修改字段名
xstore表修改字段名和行存表语法一致,使用RENAME COLUMN TO 语句增加字段。
teledb=# alter table xt rename column b to b1;
ALTER TABLE
teledb=# \d+ xt
Table "public.xt"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
--------+---------+-----------+----------+---------+----------+--------------+-------------
a | integer | | not null | | plain | |
b1 | integer | | | | plain | |
c | text | | | | extended | |
Indexes:
"xt_pkey" PRIMARY KEY, xbtree (a)
Distribute By: HASH(a)
Location Nodes: ALL DATANODES
修改表名
xstore表修改表名和行存表语法一致,使用RENAME TO 语句增加字段。
teledb=# alter table xt rename to xt_new;
ALTER TABLE
teledb=# \d+ xt
Did not find any relation named "xt".
teledb=# \d+ xt_new
Table "public.xt_new"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
--------+---------+-----------+----------+---------+----------+--------------+-------------
a | integer | | not null | | plain | |
b1 | integer | | | | plain | |
c | text | | | | extended | |
Indexes:
"xt_pkey" PRIMARY KEY, xbtree (a)
Distribute By: HASH(a)
Location Nodes: ALL DATANODES