Skip to content

Commit 70e9384

Browse files
evenyagfengjiachun
andauthored
docs: add docs for replace statement (#1628)
Co-authored-by: jeremyhi <[email protected]>
1 parent 87d4eb9 commit 70e9384

File tree

5 files changed

+91
-0
lines changed

5 files changed

+91
-0
lines changed

docs/reference/sql/overview.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
---
2+
keywords: [SQL syntax, SQL examples]
3+
description: GreptimeDB SQL statements.
4+
---
5+
16
# Overview
27

38
* [Data Types](./data-types)
@@ -13,6 +18,7 @@
1318
* [LIMIT](./limit.md)
1419
* [JOIN](./join.md)
1520
* [RANGE](./range.md)
21+
* [REPLACE](./replace.md)
1622
* [DELETE](./delete.md)
1723
* [SHOW](./show.md)
1824
* [TQL](./tql.md)

docs/reference/sql/replace.md

+39
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
keywords: [SQL REPLACE, SQL syntax, SQL examples, inserting records, SQL data manipulation]
3+
description: Describes the SQL REPLACE statement for adding records to a table in GreptimeDB, including syntax, examples for inserting single and multiple records.
4+
---
5+
6+
# REPLACE
7+
8+
The `REPLACE` statement is used to insert new records into a table. In GreptimeDB, this statement is exactly the same as the `INSERT` statement. Please refer to [`INSERT`](/reference/sql/insert.md) for more details.
9+
10+
## `REPLACE INTO` Statement
11+
12+
### Syntax
13+
14+
The syntax for the REPLACE INTO statement is as follows:
15+
16+
```sql
17+
REPLACE INTO table_name (column1, column2, column3, ...)
18+
VALUES (value1, value2, value3, ...);
19+
```
20+
21+
### Examples
22+
23+
Here is an example of an `REPLACE INTO` statement that inserts a record into a table named `system_metrics`:
24+
25+
```sql
26+
REPLACE INTO system_metrics (host, idc, cpu_util, memory_util, disk_util, ts)
27+
VALUES
28+
("host1", "idc_b", 50.0, 66.7, 40.6, 1667446797462);
29+
```
30+
31+
Here is an example of an `REPLACE INTO` statement that inserts multiple records into the `system_metrics` table:
32+
33+
```sql
34+
REPLACE INTO system_metrics (host, idc, cpu_util, memory_util, disk_util, ts)
35+
VALUES
36+
("host1", "idc_a", 11.8, 10.3, 10.3, 1667446797460),
37+
("host2", "idc_a", 80.1, 70.3, 90.0, 1667446797461),
38+
("host1", "idc_c", 50.1, 66.8, 40.8, 1667446797463);
39+
```

i18n/zh/docusaurus-plugin-content-docs/current/reference/sql/overview.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
---
2+
keywords: [SQL 语法, SQL 示例]
3+
description: GreptimeDB SQL 语句.
4+
---
5+
16
# 概述
27

38
* [数据类型](./data-types)
@@ -13,6 +18,7 @@
1318
* [LIMIT](./limit.md)
1419
* [JOIN](./join.md)
1520
* [RANGE](./range.md)
21+
* [REPLACE](./replace.md)
1622
* [DELETE](./delete.md)
1723
* [SHOW](./show.md)
1824
* [TQL](./tql.md)
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
---
2+
keywords: [SQL REPLACE 语句, SQL 语法, SQL 示例, 插入记录, SQL 数据操作]
3+
description: 描述在 GreptimeDB 中使用 SQL REPLACE 语句向表中添加记录的方法,包括语法和插入单条及多条记录的示例。
4+
---
5+
6+
# REPLACE
7+
8+
`REPLACE` 语句用于向表中插入新记录。在 GreptimeDB 中,这个语句与 `INSERT` 语句完全相同。更多详情请参考 [`INSERT`](/reference/sql/insert.md)
9+
10+
## `REPLACE INTO` 语句
11+
12+
### 语法
13+
14+
REPLACE INTO 语句的语法如下:
15+
16+
```sql
17+
REPLACE INTO table_name (column1, column2, column3, ...)
18+
VALUES (value1, value2, value3, ...);
19+
```
20+
21+
### 示例
22+
23+
以下是使用 `REPLACE INTO` 语句向名为 `system_metrics` 的表中插入一条记录的示例:
24+
25+
```sql
26+
REPLACE INTO system_metrics (host, idc, cpu_util, memory_util, disk_util, ts)
27+
VALUES
28+
("host1", "idc_b", 50.0, 66.7, 40.6, 1667446797462);
29+
```
30+
31+
以下是使用 `REPLACE INTO` 语句向 `system_metrics` 表中插入多条记录的示例:
32+
33+
```sql
34+
REPLACE INTO system_metrics (host, idc, cpu_util, memory_util, disk_util, ts)
35+
VALUES
36+
("host1", "idc_a", 11.8, 10.3, 10.3, 1667446797460),
37+
("host2", "idc_a", 80.1, 70.3, 90.0, 1667446797461),
38+
("host1", "idc_c", 50.1, 66.8, 40.8, 1667446797463);
39+
```

sidebars.ts

+1
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,7 @@ const sidebars: SidebarsConfig = {
424424
'reference/sql/limit',
425425
'reference/sql/order_by',
426426
'reference/sql/range',
427+
'reference/sql/replace',
427428
'reference/sql/select',
428429
'reference/sql/show',
429430
'reference/sql/tql',

0 commit comments

Comments
 (0)