Alias 操作
更新时间:2026-09-01
设置别名
功能介绍
为数据表设置别名。先通过 MochowClient.database(database_name) 获取数据库对象,再通过 Database.table(table_name) 获取表对象,最后调用 Table.alias(alias, config=None)。
请求示例
Python
1import pymochow
2from pymochow.auth.bce_credentials import BceCredentials
3from pymochow.configuration import Configuration
4
5account = "root"
6api_key = "your_api_key"
7endpoint = "your_endpoint" # 例如:http://127.0.0.1:8511
8
9config = Configuration(
10 credentials=BceCredentials(account, api_key),
11 endpoint=endpoint,
12)
13client = pymochow.MochowClient(config)
14
15try:
16 database = client.database("db_test")
17 table = database.table("book_vector")
18 table.alias("alias_book_vector")
19finally:
20 client.close()
请求参数
| 参数 | 参数类型 | 是否必选 | 参数含义 |
|---|---|---|---|
| alias | String | 是 | 表的别名。 |
| config | Configuration 或 dict | 否 | 本次调用使用的配置;不传时使用表对象继承的配置。 |
返回参数
| 参数 | 参数类型 | 参数含义 |
|---|---|---|
| response | HttpResponse | alias() 返回的底层响应对象。设置失败时 SDK 抛出异常。 |
删除别名
功能介绍
删除数据表的指定别名。调用方法为 Table.unalias(alias, config=None)。
请求示例
Python
1import pymochow
2from pymochow.auth.bce_credentials import BceCredentials
3from pymochow.configuration import Configuration
4
5account = "root"
6api_key = "your_api_key"
7endpoint = "your_endpoint" # 例如:http://127.0.0.1:8511
8
9config = Configuration(
10 credentials=BceCredentials(account, api_key),
11 endpoint=endpoint,
12)
13client = pymochow.MochowClient(config)
14
15try:
16 database = client.database("db_test")
17 table = database.table("book_vector")
18 table.unalias("alias_book_vector")
19finally:
20 client.close()
请求参数
| 参数 | 参数类型 | 是否必选 | 参数含义 |
|---|---|---|---|
| alias | String | 是 | 要删除的表别名。 |
| config | Configuration 或 dict | 否 | 本次调用使用的配置;不传时使用表对象继承的配置。 |
返回参数
| 参数 | 参数类型 | 参数含义 |
|---|---|---|
| response | HttpResponse | unalias() 返回的底层响应对象。删除失败时 SDK 抛出异常。 |
查询表的别名
功能介绍
SDK 没有独立的别名列表接口。通过 Database.describe_table(table_name, config=None)(或等价的便捷方法 Database.table(table_name, config=None))获取最新的 Table 对象后,可以从 Table.aliases 属性读取该表的别名列表。
请求示例
Python
1import pymochow
2from pymochow.auth.bce_credentials import BceCredentials
3from pymochow.configuration import Configuration
4
5account = "root"
6api_key = "your_api_key"
7endpoint = "your_endpoint" # 例如:http://127.0.0.1:8511
8
9config = Configuration(
10 credentials=BceCredentials(account, api_key),
11 endpoint=endpoint,
12)
13client = pymochow.MochowClient(config)
14
15try:
16 database = client.database("db_test")
17 table = database.describe_table("book_vector")
18 for alias_name in table.aliases:
19 print(alias_name)
20finally:
21 client.close()
请求参数
| 参数 | 参数类型 | 是否必选 | 参数含义 |
|---|---|---|---|
| table_name | String | 是 | 要查询的数据表名称。 |
| config | Configuration 或 dict | 否 | 本次调用使用的配置;不传时使用数据库对象继承的配置。 |
返回参数
| 参数 | 参数类型 | 参数含义 |
|---|---|---|
| table | Table | 包含服务端最新表信息的数据表对象。 |
| table.aliases | List<String> | 当前数据表的别名列表;没有别名时为空列表。 |
评价此篇文章
