修改xstore存儲表結構
更新時間 2025-02-05 09:36:50
最近更新時間: 2025-02-05 09:36:50
分享文章
本頁介紹天翼云TeleDB數據庫修改xstore存儲表結構的具體操作。
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