Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

docs: add docs for replace statement #1628

Merged
merged 5 commits into from
Apr 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/reference/sql/overview.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
keywords: [SQL syntax, SQL examples]
description: GreptimeDB SQL statements.
---

# Overview

* [Data Types](./data-types)
Expand All @@ -13,6 +18,7 @@
* [LIMIT](./limit.md)
* [JOIN](./join.md)
* [RANGE](./range.md)
* [REPLACE](./replace.md)
* [DELETE](./delete.md)
* [SHOW](./show.md)
* [TQL](./tql.md)
Expand Down
39 changes: 39 additions & 0 deletions docs/reference/sql/replace.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
keywords: [SQL REPLACE, SQL syntax, SQL examples, inserting records, SQL data manipulation]
description: Describes the SQL REPLACE statement for adding records to a table in GreptimeDB, including syntax, examples for inserting single and multiple records.
---

# REPLACE

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.

## `REPLACE INTO` Statement

### Syntax

The syntax for the REPLACE INTO statement is as follows:

```sql
REPLACE INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
```

### Examples

Here is an example of an `REPLACE INTO` statement that inserts a record into a table named `system_metrics`:

```sql
REPLACE INTO system_metrics (host, idc, cpu_util, memory_util, disk_util, ts)
VALUES
("host1", "idc_b", 50.0, 66.7, 40.6, 1667446797462);
```

Here is an example of an `REPLACE INTO` statement that inserts multiple records into the `system_metrics` table:

```sql
REPLACE INTO system_metrics (host, idc, cpu_util, memory_util, disk_util, ts)
VALUES
("host1", "idc_a", 11.8, 10.3, 10.3, 1667446797460),
("host2", "idc_a", 80.1, 70.3, 90.0, 1667446797461),
("host1", "idc_c", 50.1, 66.8, 40.8, 1667446797463);
```
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
---
keywords: [SQL 语法, SQL 示例]
description: GreptimeDB SQL 语句.
---

# 概述

* [数据类型](./data-types)
Expand All @@ -13,6 +18,7 @@
* [LIMIT](./limit.md)
* [JOIN](./join.md)
* [RANGE](./range.md)
* [REPLACE](./replace.md)
* [DELETE](./delete.md)
* [SHOW](./show.md)
* [TQL](./tql.md)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
---
keywords: [SQL REPLACE 语句, SQL 语法, SQL 示例, 插入记录, SQL 数据操作]
description: 描述在 GreptimeDB 中使用 SQL REPLACE 语句向表中添加记录的方法,包括语法和插入单条及多条记录的示例。
---

# REPLACE

`REPLACE` 语句用于向表中插入新记录。在 GreptimeDB 中,这个语句与 `INSERT` 语句完全相同。更多详情请参考 [`INSERT`](/reference/sql/insert.md)。

## `REPLACE INTO` 语句

### 语法

REPLACE INTO 语句的语法如下:

```sql
REPLACE INTO table_name (column1, column2, column3, ...)
VALUES (value1, value2, value3, ...);
```

### 示例

以下是使用 `REPLACE INTO` 语句向名为 `system_metrics` 的表中插入一条记录的示例:

```sql
REPLACE INTO system_metrics (host, idc, cpu_util, memory_util, disk_util, ts)
VALUES
("host1", "idc_b", 50.0, 66.7, 40.6, 1667446797462);
```

以下是使用 `REPLACE INTO` 语句向 `system_metrics` 表中插入多条记录的示例:

```sql
REPLACE INTO system_metrics (host, idc, cpu_util, memory_util, disk_util, ts)
VALUES
("host1", "idc_a", 11.8, 10.3, 10.3, 1667446797460),
("host2", "idc_a", 80.1, 70.3, 90.0, 1667446797461),
("host1", "idc_c", 50.1, 66.8, 40.8, 1667446797463);
```
1 change: 1 addition & 0 deletions sidebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,7 @@ const sidebars: SidebarsConfig = {
'reference/sql/limit',
'reference/sql/order_by',
'reference/sql/range',
'reference/sql/replace',
'reference/sql/select',
'reference/sql/show',
'reference/sql/tql',
Expand Down