修改列存儲表結構
更新時間 2025-02-05 09:36:50
最近更新時間: 2025-02-05 09:36:50
分享文章
本頁介紹天翼云TeleDB數據庫修改列存儲表結構的語法。
列存表修改表結構和行存表語法一致,使用ALTER TABLE 語句對指定表進行操作
ALTER TABLE table_name
其中,
增加字段
列存表修改表名和行存表語法一致,使用ADD COLUMN 語句增加字段。
teledb=# alter table t1 add column c1 int;
ALTER TABLE
teledb=# \d+ t1
Table "public.t1"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
--------+---------+-----------+----------+---------+----------+--------------+-------------
a | integer | | | | plain | |
b | integer | | | | plain | |
c | text | | | | extended | |
c1 | integer | | | | plain | |
Distribute By: HASH(a)
Location Nodes: ALL DATANODES
刪除字段
列存表修改表名和行存表語法一致,使用DROP COLUMN 語句刪除字段。
teledb=# alter table t1 drop column c1;
ALTER TABLE
teledb=# \d+ t1
Table "public.t1"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
--------+---------+-----------+----------+---------+----------+--------------+-------------
a | integer | | | | plain | |
b | integer | | | | plain | |
c | text | | | | extended | |
Distribute By: HASH(a)
Location Nodes: ALL DATANODES
修改字段名
列存表修改表名和行存表語法一致,使用RENAME COLUMN TO 語句增加字段。
teledb=# alter table t1 rename column c1 to c2;
ALTER TABLE
teledb=# \d+ t1
Table "public.t1"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
--------+---------+-----------+----------+---------+----------+--------------+-------------
a | integer | | | | plain | |
b | integer | | | | plain | |
c | text | | | | extended | |
c2 | integer | | | | plain | |
Distribute By: HASH(a)
Location Nodes: ALL DATANODES
修改列存儲表名
列存表修改表名和行存表語法一致,使用RENAME TO 語句增加字段。
teledb=# alter table t1 rename to t1_new;
ALTER TABLE
teledb=# \d+ t1
Did not find any relation named "t1".
teledb=# \d+ t1_new
Table "public.t1_new"
Column | Type | Collation | Nullable | Default | Storage | Stats target | Description
--------+---------+-----------+----------+---------+----------+--------------+-------------
a | integer | | | | plain | |
b | integer | | | | plain | |
c | text | | | | extended | |
c2 | integer | | | | plain | |
Distribute By: HASH(a)
Location Nodes: ALL DATANODES