Skip to content
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
21 changes: 19 additions & 2 deletions docs/sql-manual/sql-statements/data-modification/DML/DELETE.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ Syntax 2: This syntax can only used on UNIQUE KEY model
DELETE FROM table_name
[PARTITION partition_name | PARTITIONS (partition_name [, partition_name])]
[USING additional_tables]
WHERE condition
[WHERE condition]
[ORDER BY column [ASC | DESC] [NULLS FIRST | NULLS LAST] [, ...]]
[LIMIT [offset,] count]
```

#### Required Parameters
Expand All @@ -38,14 +40,16 @@ DELETE FROM table_name
+ column_name: column belong to table_name
+ op: Logical comparison operator, The optional types of op include: =, >, <, >=, <=, !=, in, not in
+ value | value_list: value or value list used for logial comparison
+ WHERE condition: Specifies a condition to use to select rows for removal

#### Optional Parameters

+ cte: Common Table Expression, e.g. 'WITH a AS SELECT * FROM tbl'.
+ PARTITION partition_name | PARTITIONS (partition_name [, partition_name]): Specifies the partition or partitions to select rows for removal
Comment thread
morrySnow marked this conversation as resolved.
+ table_alias: alias of table
+ USING additional_tables: If you need to refer to additional tables in the WHERE clause to help identify the rows to be removed, then specify those table names in the USING clause. You can also use the USING clause to specify subqueries that identify the rows to be removed.
+ WHERE condition: Specifies a condition to use to select rows for removal. Required for Syntax 1. Optional for Syntax 2.
+ ORDER BY column: Specifies the order in which rows are deleted. Typically used together with LIMIT to control which rows are affected.
+ LIMIT [offset,] count: Limits the number of rows to be deleted. When used with ORDER BY, deletes the first `count` rows after sorting. If `offset` is specified, skips the first `offset` rows before deleting. If used without ORDER BY, the set of affected rows is non-deterministic.

Comment thread
morrySnow marked this conversation as resolved.
Comment thread
morrySnow marked this conversation as resolved.
#### Note

Expand All @@ -59,6 +63,7 @@ This feature is supported since the Apache Doris 1.2 version
:::

5. This statement may reduce query efficiency for a period of time after execution. The degree of impact depends on the number of delete conditions specified in the statement. The more conditions you specify, the greater the impact.
6. When neither `WHERE` nor `LIMIT` is specified in Syntax 2, all rows in the table will be deleted. Always verify the intended scope before omitting the `WHERE` clause.

## Example

Expand Down Expand Up @@ -179,6 +184,18 @@ This feature is supported since the Apache Doris 1.2 version
where lineitem.o_orderkey = discount_orders.o_orderkey;
```

6. Delete with ORDER BY and LIMIT — delete the first 3 rows ordered by k1 in ascending order

```sql
DELETE FROM my_table ORDER BY k1 ASC LIMIT 3;
```
Comment thread
morrySnow marked this conversation as resolved.
Comment thread
morrySnow marked this conversation as resolved.

7. Delete with ORDER BY, LIMIT and offset — skip the first 10 rows and delete the next 5 rows ordered by k1

```sql
DELETE FROM my_table ORDER BY k1 ASC LIMIT 10, 5;
```
Comment thread
morrySnow marked this conversation as resolved.

## Keywords

DELETE
Expand Down
22 changes: 20 additions & 2 deletions docs/sql-manual/sql-statements/data-modification/DML/UPDATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,25 +18,31 @@ The UPDATE operation currently only supports updating the Value column. The upda
UPDATE target_table [table_alias]
SET assignment_list
[ FROM additional_tables]
WHERE condition
[WHERE condition]
[ORDER BY column [ASC | DESC] [NULLS FIRST | NULLS LAST] [, ...]]
[LIMIT [offset,] count]
```

#### Required Parameters

+ target_table: The target table of the data to be updated. Can be of the form 'db_name.table_name'
+ assignment_list: The target column to be updated, in the format 'col_name = value, col_name = value'
+ where condition: the condition that is expected to be updated, an expression that returns true or false can be

#### Optional Parameters

+ cte: Common Table Expression, eg 'WITH a AS SELECT * FROM tbl'
+ table_alias: alias of table
+ FROM additional_tables: Specifies one or more tables to use for selecting rows to update or for setting new values. Note that if you want use target table here, you should give it a alias explicitly.
+ WHERE condition: The condition that is expected to be updated, an expression that returns true or false.
+ ORDER BY column: Specifies the order in which rows are updated. Typically used together with LIMIT to control which rows are affected.
+ LIMIT [offset,] count: Limits the number of rows to be updated. When used with ORDER BY, updates the first `count` rows after sorting. If `offset` is specified, skips the first `offset` rows before updating. If used without ORDER BY, the set of affected rows is non-deterministic.

Comment thread
morrySnow marked this conversation as resolved.
Comment thread
morrySnow marked this conversation as resolved.
#### Note

The current UPDATE statement only supports row updates on the UNIQUE KEY model.

When neither `WHERE` nor `LIMIT` is specified, all rows in the table will be updated. Always verify the intended scope before omitting the `WHERE` clause.

## Example

The `test` table is a unique model table, which contains four columns: k1, k2, v1, v2. Where k1, k2 are keys, v1, v2 are values, and the aggregation method is Replace.
Expand Down Expand Up @@ -151,6 +157,18 @@ from discount_orders
where lineitem.o_orderkey = discount_orders.o_orderkey;
```

5. Update with ORDER BY and LIMIT — update the v1 column to 0 for the first 3 rows with the largest v1 values where k1 > 0

```sql
UPDATE test SET v1 = 0 WHERE k1 > 0 ORDER BY v1 DESC LIMIT 3;
```
Comment thread
morrySnow marked this conversation as resolved.

6. Update with ORDER BY, LIMIT and offset — skip the first 10 rows and update the next 5 rows ordered by k1

```sql
UPDATE test SET v1 = 100 ORDER BY k1 ASC LIMIT 10, 5;
```

## Keywords

UPDATE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ column_name op { value | value_list } [ AND column_name op { value | value_list
DELETE FROM table_name [table_alias]
[PARTITION partition_name | PARTITIONS (partition_name [, partition_name])]
[USING additional_tables]
WHERE condition
[WHERE condition]
[ORDER BY column [ASC | DESC] [NULLS FIRST | NULLS LAST] [, ...]]
[LIMIT [offset,] count]
```

#### Required Parameters
Expand All @@ -38,14 +40,16 @@ DELETE FROM table_name [table_alias]
+ column_name: 属于 table_name 的列
+ op: 逻辑比较操作符,可选类型包括:=, >, <, >=, <=, !=, in, not in
+ value | value_list: 做逻辑比较的值或值列表
+ WHERE condition: 指定一个用于选择删除行的条件

#### Optional Parameters

+ cte: 通用表达式。可以是 'WITH a AS SELECT * FROM tbl' 形式
+ PARTITION partition_name | PARTITIONS (partition_name [, partition_name]): 指定执行删除数据的分区名,如果表不存在此分区,则报错
Comment thread
morrySnow marked this conversation as resolved.
+ table_alias: 表的别名
+ USING additional_tables: 如果需要在 WHERE 语句中使用其他的表来帮助识别需要删除的行,则可以在 USING 中指定这些表或者查询。
+ WHERE condition: 指定一个用于选择删除行的条件。语法一中为必填项,语法二中为可选项。
+ ORDER BY column: 指定删除行的排序方式。通常与 LIMIT 一起使用,以控制哪些行会被删除。
+ LIMIT [offset,] count: 限制删除的行数。与 ORDER BY 一起使用时,排序后删除前 `count` 行。如果指定了 `offset`,则跳过排序后的前 `offset` 行再进行删除。如果不配合 ORDER BY 使用,受影响的行是不确定的。

Comment thread
morrySnow marked this conversation as resolved.
#### Note

Expand All @@ -54,6 +58,7 @@ DELETE FROM table_name [table_alias]
3. 语法一中,条件之间只能是“与”的关系。若希望达成“或”的关系,需要将条件分写在两个 DELETE 语句中。
4. 语法一中,如果为分区表,需要指定分区,如果不指定,doris 会从条件中推断出分区。两种情况下,doris 无法从条件中推断出分区:1) 条件中不包含分区列;2) 分区列的 op 为 not in。如果分区表不是 Unique 表,当分区表未指定分区,或者无法从条件中推断分区的时候,需要设置会话变量 delete_without_partition 为 true,此时 delete 会应用到所有分区。
5. 该语句可能会降低执行后一段时间内的查询效率。影响程度取决于语句中指定的删除条件的数量。指定的条件越多,影响越大。
6. 在语法二中,如果既未指定 `WHERE` 也未指定 `LIMIT`,则会删除表中的所有行。请在省略 `WHERE` 子句前务必确认操作范围。

## 示例

Expand Down Expand Up @@ -174,6 +179,18 @@ DELETE FROM table_name [table_alias]
where lineitem.o_orderkey = discount_orders.o_orderkey;
```

6. 使用 ORDER BY 和 LIMIT 删除数据——按照 k1 列升序排列,删除前 3 行

```sql
DELETE FROM my_table ORDER BY k1 ASC LIMIT 3;
```
Comment thread
morrySnow marked this conversation as resolved.

7. 使用 ORDER BY、LIMIT 和 offset 删除数据——按照 k1 列升序排列,跳过前 10 行,删除接下来的 5 行

```sql
DELETE FROM my_table ORDER BY k1 ASC LIMIT 10, 5;
```

## 关键词

DELETE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,31 @@ UPDATE 操作目前只支持更新 Value 列,Key 列的更新可参考[使用
UPDATE target_table [table_alias]
SET assignment_list
[ FROM additional_tables]
WHERE condition
[WHERE condition]
[ORDER BY column [ASC | DESC] [NULLS FIRST | NULLS LAST] [, ...]]
[LIMIT [offset,] count]
```

#### Required Parameters

+ target_table: 待更新数据的目标表。可以是 'db_name.table_name' 形式
+ assignment_list: 待更新的目标列,形如 'col_name = value, col_name = value' 格式
+ WHERE condition: 期望更新的条件,一个返回 true 或者 false 的表达式即可

#### Optional Parameters

+ cte: 通用表达式。可以是 'WITH a AS SELECT * FROM tbl' 形式
+ table_alias: 表的别名
+ FROM additional_tables: 指定一个或多个表,用于选中更新的行,或者获取更新的值。注意,如需要在此列表中再次使用目标表,需要为其显式指定别名。
+ WHERE condition: 期望更新的条件,一个返回 true 或者 false 的表达式即可。
+ ORDER BY column: 指定更新行的排序方式。通常与 LIMIT 一起使用,以控制哪些行会被更新。
+ LIMIT [offset,] count: 限制更新的行数。与 ORDER BY 一起使用时,排序后更新前 `count` 行。如果指定了 `offset`,则跳过排序后的前 `offset` 行再进行更新。如果不配合 ORDER BY 使用,受影响的行是不确定的。

Comment thread
morrySnow marked this conversation as resolved.
#### Note

当前 UPDATE 语句仅支持在 UNIQUE KEY 模型上的行更新。

如果既未指定 `WHERE` 也未指定 `LIMIT`,则会更新表中的所有行。请在省略 `WHERE` 子句前务必确认操作范围。

## 示例

`test` 表是一个 unique 模型的表,包含:k1, k2, v1, v2 四个列。其中 k1, k2 是 key,v1, v2 是 value,聚合方式是 Replace。
Expand Down Expand Up @@ -152,6 +158,18 @@ from discount_orders
where lineitem.o_orderkey = discount_orders.o_orderkey;
```

5. 使用 ORDER BY 和 LIMIT 更新数据——按照 v1 列降序排列,更新满足 k1 > 0 条件的前 3 行的 v1 列为 0

```sql
UPDATE test SET v1 = 0 WHERE k1 > 0 ORDER BY v1 DESC LIMIT 3;
```

6. 使用 ORDER BY、LIMIT 和 offset 更新数据——按照 k1 列升序排列,跳过前 10 行,更新接下来的 5 行

```sql
UPDATE test SET v1 = 100 ORDER BY k1 ASC LIMIT 10, 5;
```

## 关键词

UPDATE
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ column_name op { value | value_list } [ AND column_name op { value | value_list
DELETE FROM table_name [table_alias]
[PARTITION partition_name | PARTITIONS (partition_name [, partition_name])]
[USING additional_tables]
WHERE condition
[WHERE condition]
[ORDER BY column [ASC | DESC] [NULLS FIRST | NULLS LAST] [, ...]]
[LIMIT [offset,] count]
```

#### Required Parameters
Expand All @@ -38,14 +40,20 @@ DELETE FROM table_name [table_alias]
+ column_name: 属于 table_name 的列
+ op: 逻辑比较操作符,可选类型包括:=, >, <, >=, <=, !=, in, not in
+ value | value_list: 做逻辑比较的值或值列表
+ WHERE condition: 指定一个用于选择删除行的条件

#### Optional Parameters

+ cte: 通用表达式。可以是 'WITH a AS SELECT * FROM tbl' 形式
+ PARTITION partition_name | PARTITIONS (partition_name [, partition_name]): 指定执行删除数据的分区名,如果表不存在此分区,则报错
Comment thread
morrySnow marked this conversation as resolved.
+ table_alias: 表的别名
+ USING additional_tables: 如果需要在 WHERE 语句中使用其他的表来帮助识别需要删除的行,则可以在 USING 中指定这些表或者查询。
+ WHERE condition: 指定一个用于选择删除行的条件。语法一中为必填项,语法二中为可选项。
+ ORDER BY column: 指定删除行的排序方式。通常与 LIMIT 一起使用,以控制哪些行会被删除。
+ LIMIT [offset,] count: 限制删除的行数。与 ORDER BY 一起使用时,排序后删除前 `count` 行。如果指定了 `offset`,则跳过排序后的前 `offset` 行再进行删除。如果不配合 ORDER BY 使用,受影响的行是不确定的。

:::tip
DELETE 语句中的 ORDER BY 和 LIMIT 自 4.1.0 版本起支持。
:::

#### Note

Expand All @@ -54,6 +62,7 @@ DELETE FROM table_name [table_alias]
3. 语法一中,条件之间只能是“与”的关系。若希望达成“或”的关系,需要将条件分写在两个 DELETE 语句中。
4. 语法一中,如果为分区表,需要指定分区,如果不指定,doris 会从条件中推断出分区。两种情况下,doris 无法从条件中推断出分区:1) 条件中不包含分区列;2) 分区列的 op 为 not in。如果分区表不是 Unique 表,当分区表未指定分区,或者无法从条件中推断分区的时候,需要设置会话变量 delete_without_partition 为 true,此时 delete 会应用到所有分区。
5. 该语句可能会降低执行后一段时间内的查询效率。影响程度取决于语句中指定的删除条件的数量。指定的条件越多,影响越大。
6. 在语法二中,如果既未指定 `WHERE` 也未指定 `LIMIT`,则会删除表中的所有行。请在省略 `WHERE` 子句前务必确认操作范围。

## 示例

Expand Down Expand Up @@ -174,6 +183,18 @@ DELETE FROM table_name [table_alias]
where lineitem.o_orderkey = discount_orders.o_orderkey;
```

6. 使用 ORDER BY 和 LIMIT 删除数据——按照 k1 列升序排列,删除前 3 行
Comment thread
morrySnow marked this conversation as resolved.

```sql
DELETE FROM my_table ORDER BY k1 ASC LIMIT 3;
```

7. 使用 ORDER BY、LIMIT 和 offset 删除数据——按照 k1 列升序排列,跳过前 10 行,删除接下来的 5 行

```sql
DELETE FROM my_table ORDER BY k1 ASC LIMIT 10, 5;
```

## 关键词

DELETE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,25 +19,35 @@ UPDATE 操作目前只支持更新 Value 列,Key 列的更新可参考[使用
UPDATE target_table [table_alias]
SET assignment_list
[ FROM additional_tables]
WHERE condition
[WHERE condition]
[ORDER BY column [ASC | DESC] [NULLS FIRST | NULLS LAST] [, ...]]
[LIMIT [offset,] count]
```

#### Required Parameters

+ target_table: 待更新数据的目标表。可以是 'db_name.table_name' 形式
+ assignment_list: 待更新的目标列,形如 'col_name = value, col_name = value' 格式
+ WHERE condition: 期望更新的条件,一个返回 true 或者 false 的表达式即可

#### Optional Parameters

+ cte: 通用表达式。可以是 'WITH a AS SELECT * FROM tbl' 形式
+ table_alias: 表的别名
+ FROM additional_tables: 指定一个或多个表,用于选中更新的行,或者获取更新的值。注意,如需要在此列表中再次使用目标表,需要为其显式指定别名。
+ WHERE condition: 期望更新的条件,一个返回 true 或者 false 的表达式即可。
+ ORDER BY column: 指定更新行的排序方式。通常与 LIMIT 一起使用,以控制哪些行会被更新。
+ LIMIT [offset,] count: 限制更新的行数。与 ORDER BY 一起使用时,排序后更新前 `count` 行。如果指定了 `offset`,则跳过排序后的前 `offset` 行再进行更新。如果不配合 ORDER BY 使用,受影响的行是不确定的。

:::tip
UPDATE 语句中的 ORDER BY 和 LIMIT 自 4.1.0 版本起支持。
:::

#### Note

当前 UPDATE 语句仅支持在 UNIQUE KEY 模型上的行更新。

如果既未指定 `WHERE` 也未指定 `LIMIT`,则会更新表中的所有行。请在省略 `WHERE` 子句前务必确认操作范围。

## 示例

`test` 表是一个 unique 模型的表,包含:k1, k2, v1, v2 四个列。其中 k1, k2 是 key,v1, v2 是 value,聚合方式是 Replace。
Expand Down Expand Up @@ -152,6 +162,18 @@ from discount_orders
where lineitem.o_orderkey = discount_orders.o_orderkey;
```

5. 使用 ORDER BY 和 LIMIT 更新数据——按照 v1 列降序排列,更新满足 k1 > 0 条件的前 3 行的 v1 列为 0

```sql
UPDATE test SET v1 = 0 WHERE k1 > 0 ORDER BY v1 DESC LIMIT 3;
```

6. 使用 ORDER BY、LIMIT 和 offset 更新数据——按照 k1 列升序排列,跳过前 10 行,更新接下来的 5 行

```sql
UPDATE test SET v1 = 100 ORDER BY k1 ASC LIMIT 10, 5;
```

## 关键词

UPDATE
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ Syntax 2: This syntax can only used on UNIQUE KEY model
DELETE FROM table_name
[PARTITION partition_name | PARTITIONS (partition_name [, partition_name])]
[USING additional_tables]
WHERE condition
[WHERE condition]
[ORDER BY column [ASC | DESC] [NULLS FIRST | NULLS LAST] [, ...]]
[LIMIT [offset,] count]
```

#### Required Parameters
Expand All @@ -38,14 +40,20 @@ DELETE FROM table_name
+ column_name: column belong to table_name
+ op: Logical comparison operator, The optional types of op include: =, >, <, >=, <=, !=, in, not in
+ value | value_list: value or value list used for logial comparison
+ WHERE condition: Specifies a condition to use to select rows for removal

#### Optional Parameters

+ cte: Common Table Expression, e.g. 'WITH a AS SELECT * FROM tbl'.
+ PARTITION partition_name | PARTITIONS (partition_name [, partition_name]): Specifies the partition or partitions to select rows for removal
Comment thread
morrySnow marked this conversation as resolved.
+ table_alias: alias of table
+ USING additional_tables: If you need to refer to additional tables in the WHERE clause to help identify the rows to be removed, then specify those table names in the USING clause. You can also use the USING clause to specify subqueries that identify the rows to be removed.
+ WHERE condition: Specifies a condition to use to select rows for removal. Required for Syntax 1. Optional for Syntax 2.
+ ORDER BY column: Specifies the order in which rows are deleted. Typically used together with LIMIT to control which rows are affected.
+ LIMIT [offset,] count: Limits the number of rows to be deleted. When used with ORDER BY, deletes the first `count` rows after sorting. If `offset` is specified, skips the first `offset` rows before deleting. If used without ORDER BY, the set of affected rows is non-deterministic.

:::tip
ORDER BY and LIMIT in DELETE statements are supported since version 4.1.0.
:::

#### Note

Expand All @@ -59,6 +67,7 @@ This feature is supported since the Apache Doris 1.2 version
:::

5. This statement may reduce query efficiency for a period of time after execution. The degree of impact depends on the number of delete conditions specified in the statement. The more conditions you specify, the greater the impact.
6. When neither `WHERE` nor `LIMIT` is specified in Syntax 2, all rows in the table will be deleted. Always verify the intended scope before omitting the `WHERE` clause.

## Example

Expand Down Expand Up @@ -179,6 +188,18 @@ This feature is supported since the Apache Doris 1.2 version
where lineitem.o_orderkey = discount_orders.o_orderkey;
```

6. Delete with ORDER BY and LIMIT — delete the first 3 rows ordered by k1 in ascending order
Comment thread
morrySnow marked this conversation as resolved.

```sql
DELETE FROM my_table ORDER BY k1 ASC LIMIT 3;
```

7. Delete with ORDER BY, LIMIT and offset — skip the first 10 rows and delete the next 5 rows ordered by k1

```sql
DELETE FROM my_table ORDER BY k1 ASC LIMIT 10, 5;
```

## Keywords

DELETE
Expand Down
Loading
Loading