Skip to content

Commit f3c2941

Browse files
Copilotfengjiachunwaynexia
authored
docs: add documentation for COMMENT ON statement (#2260)
Co-authored-by: copilot-swe-agent[bot] <198982749+Copilot@users.noreply.github.com> Co-authored-by: fengjiachun <3860496+fengjiachun@users.noreply.github.com> Co-authored-by: waynexia <15380403+waynexia@users.noreply.github.com>
1 parent f123e13 commit f3c2941

File tree

6 files changed

+526
-0
lines changed

6 files changed

+526
-0
lines changed

docs/reference/sql/comment.md

Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
---
2+
keywords: [SQL COMMENT, COMMENT ON TABLE, COMMENT ON COLUMN, COMMENT ON FLOW, SQL syntax, SQL examples]
3+
description: Covers the SQL COMMENT statement for adding or removing comments on tables, columns, and flows in GreptimeDB, including syntax and examples.
4+
---
5+
6+
# COMMENT
7+
8+
The `COMMENT` statement is used to add or remove comments on tables, columns, and flows. Comments provide descriptions that can help document the purpose and usage of database objects.
9+
10+
## COMMENT ON TABLE
11+
12+
`COMMENT ON TABLE` adds or removes a comment on a table.
13+
14+
### Syntax
15+
16+
```sql
17+
COMMENT ON TABLE table_name IS { 'comment' | NULL }
18+
```
19+
20+
- `table_name`: The name of the table to comment on.
21+
- `'comment'`: A string literal containing the comment text.
22+
- `NULL`: Removes the existing comment from the table.
23+
24+
### Examples
25+
26+
Add a comment to a table:
27+
28+
```sql
29+
COMMENT ON TABLE system_metrics IS 'System monitoring metrics collected every minute';
30+
```
31+
32+
Remove a comment from a table:
33+
34+
```sql
35+
COMMENT ON TABLE system_metrics IS NULL;
36+
```
37+
38+
View the table comment using `SHOW CREATE TABLE`:
39+
40+
```sql
41+
SHOW CREATE TABLE system_metrics;
42+
```
43+
44+
The comment can also be viewed through the `INFORMATION_SCHEMA.TABLES` table by querying the `table_comment` column.
45+
46+
## COMMENT ON COLUMN
47+
48+
`COMMENT ON COLUMN` adds or removes a comment on a specific column of a table.
49+
50+
### Syntax
51+
52+
```sql
53+
COMMENT ON COLUMN table_name.column_name IS { 'comment' | NULL }
54+
```
55+
56+
- `table_name`: The name of the table containing the column.
57+
- `column_name`: The name of the column to comment on.
58+
- `'comment'`: A string literal containing the comment text.
59+
- `NULL`: Removes the existing comment from the column.
60+
61+
### Examples
62+
63+
Add a comment to a column:
64+
65+
```sql
66+
COMMENT ON COLUMN system_metrics.cpu_usage IS 'CPU usage percentage (0-100)';
67+
```
68+
69+
Add comments to multiple columns:
70+
71+
```sql
72+
COMMENT ON COLUMN system_metrics.memory_usage IS 'Memory usage in bytes';
73+
COMMENT ON COLUMN system_metrics.disk_usage IS 'Disk usage percentage';
74+
```
75+
76+
Remove a comment from a column:
77+
78+
```sql
79+
COMMENT ON COLUMN system_metrics.cpu_usage IS NULL;
80+
```
81+
82+
View column comments using `SHOW CREATE TABLE`:
83+
84+
```sql
85+
SHOW CREATE TABLE system_metrics;
86+
```
87+
88+
Column comments can also be queried from the `INFORMATION_SCHEMA.COLUMNS` table by accessing the `column_comment` column.
89+
90+
## COMMENT ON FLOW
91+
92+
`COMMENT ON FLOW` adds or removes a comment on a flow.
93+
94+
### Syntax
95+
96+
```sql
97+
COMMENT ON FLOW flow_name IS { 'comment' | NULL }
98+
```
99+
100+
- `flow_name`: The name of the flow to comment on.
101+
- `'comment'`: A string literal containing the comment text.
102+
- `NULL`: Removes the existing comment from the flow.
103+
104+
### Examples
105+
106+
Add a comment to a flow:
107+
108+
```sql
109+
COMMENT ON FLOW temperature_monitoring IS 'Monitors temperature sensors and alerts on high values';
110+
```
111+
112+
Remove a comment from a flow:
113+
114+
```sql
115+
COMMENT ON FLOW temperature_monitoring IS NULL;
116+
```
117+
118+
View the flow comment using `SHOW CREATE FLOW`:
119+
120+
```sql
121+
SHOW CREATE FLOW temperature_monitoring;
122+
```
123+
124+
Flow comments can also be queried from the `INFORMATION_SCHEMA.FLOWS` table by accessing the `comment` column.
125+
126+
## Notes
127+
128+
- Comments are stored as metadata and do not affect the behavior or performance of tables, columns, or flows.
129+
- Comments can be updated by issuing a new `COMMENT ON` statement with a different comment text.
130+
- Setting a comment to `NULL` removes the existing comment but does not generate an error if no comment exists.
131+
- Comments are particularly useful for documenting the purpose of database objects, especially in collaborative environments.
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
---
2+
keywords: [SQL COMMENT 语句, COMMENT ON TABLE, COMMENT ON COLUMN, COMMENT ON FLOW, SQL 语法, SQL 示例]
3+
description: COMMENT 语句用于在 GreptimeDB 中为表、列和流添加或删除注释,包括语法和示例。
4+
---
5+
6+
# COMMENT
7+
8+
`COMMENT` 语句用于为表、列和流添加或删除注释。注释提供的描述可以帮助记录数据库对象的用途和使用方法。
9+
10+
## COMMENT ON TABLE
11+
12+
`COMMENT ON TABLE` 用于为表添加或删除注释。
13+
14+
### 语法
15+
16+
```sql
17+
COMMENT ON TABLE table_name IS { 'comment' | NULL }
18+
```
19+
20+
- `table_name`: 要添加注释的表名。
21+
- `'comment'`: 包含注释文本的字符串。
22+
- `NULL`: 删除表的现有注释。
23+
24+
### 示例
25+
26+
为表添加注释:
27+
28+
```sql
29+
COMMENT ON TABLE system_metrics IS 'System monitoring metrics collected every minute';
30+
```
31+
32+
删除表的注释:
33+
34+
```sql
35+
COMMENT ON TABLE system_metrics IS NULL;
36+
```
37+
38+
使用 `SHOW CREATE TABLE` 查看表注释:
39+
40+
```sql
41+
SHOW CREATE TABLE system_metrics;
42+
```
43+
44+
也可以通过查询 `INFORMATION_SCHEMA.TABLES` 表的 `table_comment` 列来查看注释。
45+
46+
## COMMENT ON COLUMN
47+
48+
`COMMENT ON COLUMN` 用于为表的特定列添加或删除注释。
49+
50+
### 语法
51+
52+
```sql
53+
COMMENT ON COLUMN table_name.column_name IS { 'comment' | NULL }
54+
```
55+
56+
- `table_name`: 包含该列的表名。
57+
- `column_name`: 要添加注释的列名。
58+
- `'comment'`: 包含注释文本的字符串。
59+
- `NULL`: 删除列的现有注释。
60+
61+
### 示例
62+
63+
为列添加注释:
64+
65+
```sql
66+
COMMENT ON COLUMN system_metrics.cpu_usage IS 'CPU usage percentage (0-100)';
67+
```
68+
69+
为多个列添加注释:
70+
71+
```sql
72+
COMMENT ON COLUMN system_metrics.memory_usage IS 'Memory usage in bytes';
73+
COMMENT ON COLUMN system_metrics.disk_usage IS 'Disk usage percentage';
74+
```
75+
76+
删除列的注释:
77+
78+
```sql
79+
COMMENT ON COLUMN system_metrics.cpu_usage IS NULL;
80+
```
81+
82+
使用 `SHOW CREATE TABLE` 查看列注释:
83+
84+
```sql
85+
SHOW CREATE TABLE system_metrics;
86+
```
87+
88+
也可以通过查询 `INFORMATION_SCHEMA.COLUMNS` 表的 `column_comment` 列来查看列注释。
89+
90+
## COMMENT ON FLOW
91+
92+
`COMMENT ON FLOW` 用于为流添加或删除注释。
93+
94+
### 语法
95+
96+
```sql
97+
COMMENT ON FLOW flow_name IS { 'comment' | NULL }
98+
```
99+
100+
- `flow_name`: 要添加注释的流名称。
101+
- `'comment'`: 包含注释文本的字符串。
102+
- `NULL`: 删除流的现有注释。
103+
104+
### 示例
105+
106+
为流添加注释:
107+
108+
```sql
109+
COMMENT ON FLOW temperature_monitoring IS 'Monitors temperature sensors and alerts on high values';
110+
```
111+
112+
删除流的注释:
113+
114+
```sql
115+
COMMENT ON FLOW temperature_monitoring IS NULL;
116+
```
117+
118+
使用 `SHOW CREATE FLOW` 查看流注释:
119+
120+
```sql
121+
SHOW CREATE FLOW temperature_monitoring;
122+
```
123+
124+
也可以通过查询 `INFORMATION_SCHEMA.FLOWS` 表的 `comment` 列来查看流注释。
125+
126+
## 注意事项
127+
128+
- 注释作为元数据存储,不会影响表、列或流的行为或性能。
129+
- 可以通过发出新的 `COMMENT ON` 语句来更新注释。
130+
- 将注释设置为 `NULL` 会删除现有注释,如果注释不存在也不会产生错误。
131+
- 注释对于记录数据库对象的用途特别有用,特别是在协作环境中。
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
---
2+
keywords: [SQL COMMENT 语句, COMMENT ON TABLE, COMMENT ON COLUMN, COMMENT ON FLOW, SQL 语法, SQL 示例]
3+
description: COMMENT 语句用于在 GreptimeDB 中为表、列和流添加或删除注释,包括语法和示例。
4+
---
5+
6+
# COMMENT
7+
8+
`COMMENT` 语句用于为表、列和流添加或删除注释。注释提供的描述可以帮助记录数据库对象的用途和使用方法。
9+
10+
## COMMENT ON TABLE
11+
12+
`COMMENT ON TABLE` 用于为表添加或删除注释。
13+
14+
### 语法
15+
16+
```sql
17+
COMMENT ON TABLE table_name IS { 'comment' | NULL }
18+
```
19+
20+
- `table_name`: 要添加注释的表名。
21+
- `'comment'`: 包含注释文本的字符串。
22+
- `NULL`: 删除表的现有注释。
23+
24+
### 示例
25+
26+
为表添加注释:
27+
28+
```sql
29+
COMMENT ON TABLE system_metrics IS 'System monitoring metrics collected every minute';
30+
```
31+
32+
删除表的注释:
33+
34+
```sql
35+
COMMENT ON TABLE system_metrics IS NULL;
36+
```
37+
38+
使用 `SHOW CREATE TABLE` 查看表注释:
39+
40+
```sql
41+
SHOW CREATE TABLE system_metrics;
42+
```
43+
44+
也可以通过查询 `INFORMATION_SCHEMA.TABLES` 表的 `table_comment` 列来查看注释。
45+
46+
## COMMENT ON COLUMN
47+
48+
`COMMENT ON COLUMN` 用于为表的特定列添加或删除注释。
49+
50+
### 语法
51+
52+
```sql
53+
COMMENT ON COLUMN table_name.column_name IS { 'comment' | NULL }
54+
```
55+
56+
- `table_name`: 包含该列的表名。
57+
- `column_name`: 要添加注释的列名。
58+
- `'comment'`: 包含注释文本的字符串。
59+
- `NULL`: 删除列的现有注释。
60+
61+
### 示例
62+
63+
为列添加注释:
64+
65+
```sql
66+
COMMENT ON COLUMN system_metrics.cpu_usage IS 'CPU usage percentage (0-100)';
67+
```
68+
69+
为多个列添加注释:
70+
71+
```sql
72+
COMMENT ON COLUMN system_metrics.memory_usage IS 'Memory usage in bytes';
73+
COMMENT ON COLUMN system_metrics.disk_usage IS 'Disk usage percentage';
74+
```
75+
76+
删除列的注释:
77+
78+
```sql
79+
COMMENT ON COLUMN system_metrics.cpu_usage IS NULL;
80+
```
81+
82+
使用 `SHOW CREATE TABLE` 查看列注释:
83+
84+
```sql
85+
SHOW CREATE TABLE system_metrics;
86+
```
87+
88+
也可以通过查询 `INFORMATION_SCHEMA.COLUMNS` 表的 `column_comment` 列来查看列注释。
89+
90+
## COMMENT ON FLOW
91+
92+
`COMMENT ON FLOW` 用于为流添加或删除注释。
93+
94+
### 语法
95+
96+
```sql
97+
COMMENT ON FLOW flow_name IS { 'comment' | NULL }
98+
```
99+
100+
- `flow_name`: 要添加注释的流名称。
101+
- `'comment'`: 包含注释文本的字符串。
102+
- `NULL`: 删除流的现有注释。
103+
104+
### 示例
105+
106+
为流添加注释:
107+
108+
```sql
109+
COMMENT ON FLOW temperature_monitoring IS 'Monitors temperature sensors and alerts on high values';
110+
```
111+
112+
删除流的注释:
113+
114+
```sql
115+
COMMENT ON FLOW temperature_monitoring IS NULL;
116+
```
117+
118+
使用 `SHOW CREATE FLOW` 查看流注释:
119+
120+
```sql
121+
SHOW CREATE FLOW temperature_monitoring;
122+
```
123+
124+
也可以通过查询 `INFORMATION_SCHEMA.FLOWS` 表的 `comment` 列来查看流注释。
125+
126+
## 注意事项
127+
128+
- 注释作为元数据存储,不会影响表、列或流的行为或性能。
129+
- 可以通过发出新的 `COMMENT ON` 语句来更新注释。
130+
- 将注释设置为 `NULL` 会删除现有注释,如果注释不存在也不会产生错误。
131+
- 注释对于记录数据库对象的用途特别有用,特别是在协作环境中。

0 commit comments

Comments
 (0)