修改列存储表结构
 
                  更新时间 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
