修改表
本文介绍如何使用 Table 对象对已有表进行修改操作,包括重命名、修改生命 周期、增删列、更改列类型等。
前置条件
所有修改操作都需要先获取 Table 实例:
- Java
- Python
- Go
Odps odps = new Odps(...);
Table table = odps.tables().get("project_name", "table_name");
from odps import ODPS
odps = ODPS(...)
table = odps.get_table('table_name', project='project_name')
odpsIns := odps.NewOdps(account, endpoint)
odpsIns.SetDefaultProjectName("project_name")
table := odpsIns.Tables().Get("table_name")
重命名表
- Java
- Python
- Go
public void rename(String newName) throws Exception
table.rename(new_name)
func (t *Table) Rename(newName string) error
将表重命名为新名称,新名称必须符合 MaxCompute 命名规则。
- Java
- Python
- Go
table.rename("new_table_name");
table.rename('new_table_name')
err := table.Rename("new_table_name")
修改生命周期
- Java
- Python
- Go
public void setLifeCycle(int days) throws OdpsException
table.set_lifecycle(days)
func (t *Table) SetLifeCycle(days int) error
修改表的生命周期,单位为天,必须为正整数。
- Java
- Python
- Go
// 设置生命周期为 90 天
table.setLifeCycle(90);