-
Notifications
You must be signed in to change notification settings - Fork 29.3k
[SPARK-58519][SQL] Document UPDATE and DELETE FROM statements #57725
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,101 @@ | ||
| --- | ||
| layout: global | ||
| title: DELETE FROM | ||
| displayTitle: DELETE FROM | ||
| license: | | ||
| Licensed to the Apache Software Foundation (ASF) under one or more | ||
| contributor license agreements. See the NOTICE file distributed with | ||
| this work for additional information regarding copyright ownership. | ||
| The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| (the "License"); you may not use this file except in compliance with | ||
| the License. You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| --- | ||
|
|
||
| ### Description | ||
|
|
||
| The `DELETE FROM` statement removes rows from a table that satisfy an optional condition. When no | ||
| condition is specified, every row is removed. | ||
|
|
||
| `DELETE FROM` is supported on tables backed by | ||
| [Data Source V2](sql-v2-data-sources.html#row-level-dml) connectors that support delete operations. | ||
|
|
||
| ### Syntax | ||
|
|
||
| ```sql | ||
| DELETE FROM table_identifier [ [ AS ] table_alias ] | ||
| [ WITH ( key = value [ , ... ] ) ] | ||
| [ WHERE boolean_expression ] | ||
| ``` | ||
|
|
||
| ### Parameters | ||
|
|
||
| * **table_identifier** | ||
|
|
||
| Specifies the table from which rows are deleted. The table name may be optionally qualified | ||
| with a database name. | ||
|
|
||
| **Syntax:** `[ database_name. ] table_name` | ||
|
|
||
| * **table_alias** | ||
|
|
||
| Specifies an optional alias for the target table. The alias may be introduced with or without | ||
| the `AS` keyword. | ||
|
|
||
| * **WITH ( key = value [ , ... ] )** | ||
|
|
||
| Specifies an optional list of dynamic table options passed to the Data Source V2 connector for | ||
| this statement only. The options allow per-statement tuning without changing the table's | ||
| persistent configuration. Keys and values are treated as strings; a key that is not a valid | ||
| identifier can be quoted with backticks. Spark passes options through without validating their | ||
| names, and connectors may ignore options they do not recognize. | ||
|
|
||
| * **WHERE boolean_expression** | ||
|
|
||
| Specifies an optional condition that selects the rows to delete. If the `WHERE` clause is | ||
| omitted, all rows are deleted. | ||
|
|
||
| ### Examples | ||
|
|
||
| The following examples assume that an `employees` table has already been created and populated. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same as the |
||
|
|
||
| #### Delete Rows Matching a Condition | ||
|
|
||
| ```sql | ||
| DELETE FROM employees WHERE status = 'inactive'; | ||
| ``` | ||
|
|
||
| #### Delete Rows Using an Alias | ||
|
|
||
| ```sql | ||
| DELETE FROM employees AS e | ||
| WHERE e.department = 'Sales' AND e.last_active_date < DATE '2025-01-01'; | ||
| ``` | ||
|
|
||
| #### Delete Using Dynamic Table Options | ||
|
|
||
| ```sql | ||
| -- Option names and values are specific to the table's data source connector. | ||
| DELETE FROM employees WITH (`write.split-size` = 10) | ||
| WHERE status = 'inactive'; | ||
| ``` | ||
|
|
||
| #### Delete All Rows | ||
|
|
||
| ```sql | ||
| DELETE FROM employees; | ||
| ``` | ||
|
|
||
| ### Related Statements | ||
|
|
||
| * [INSERT TABLE statement](sql-ref-syntax-dml-insert-table.html) | ||
| * [MERGE INTO statement](sql-ref-syntax-dml-merge-into.html) | ||
| * [SELECT statement](sql-ref-syntax-qry-select.html) | ||
| * [UPDATE statement](sql-ref-syntax-dml-update.html) | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,113 @@ | ||
| --- | ||
| layout: global | ||
| title: UPDATE | ||
| displayTitle: UPDATE | ||
| license: | | ||
| Licensed to the Apache Software Foundation (ASF) under one or more | ||
| contributor license agreements. See the NOTICE file distributed with | ||
| this work for additional information regarding copyright ownership. | ||
| The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| (the "License"); you may not use this file except in compliance with | ||
| the License. You may obtain a copy of the License at | ||
|
|
||
| http://www.apache.org/licenses/LICENSE-2.0 | ||
|
|
||
| Unless required by applicable law or agreed to in writing, software | ||
| distributed under the License is distributed on an "AS IS" BASIS, | ||
| WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| See the License for the specific language governing permissions and | ||
| limitations under the License. | ||
| --- | ||
|
|
||
| ### Description | ||
|
|
||
| The `UPDATE` statement changes the values of columns in rows that satisfy an optional condition. | ||
| When no condition is specified, every row is updated. | ||
|
|
||
| `UPDATE` is supported on tables backed by | ||
| [Data Source V2](sql-v2-data-sources.html#row-level-dml) connectors that support row-level | ||
| operations. | ||
|
|
||
| ### Syntax | ||
|
|
||
| ```sql | ||
| UPDATE table_identifier [ [ AS ] table_alias ] | ||
| [ WITH ( key = value [ , ... ] ) ] | ||
| SET column = value [ , ... ] | ||
| [ WHERE boolean_expression ] | ||
| ``` | ||
|
|
||
| ### Parameters | ||
|
|
||
| * **table_identifier** | ||
|
|
||
| Specifies the table to update, which may be optionally qualified with a database name. | ||
|
|
||
| **Syntax:** `[ database_name. ] table_name` | ||
|
|
||
| * **table_alias** | ||
|
|
||
| Specifies an optional alias for the target table. The alias may be introduced with or without | ||
| the `AS` keyword. | ||
|
|
||
| * **WITH ( key = value [ , ... ] )** | ||
|
|
||
| Specifies an optional list of dynamic table options passed to the Data Source V2 connector for | ||
| this statement only. The options allow per-statement tuning without changing the table's | ||
| persistent configuration. Keys and values are treated as strings; a key that is not a valid | ||
| identifier can be quoted with backticks. Spark passes options through without validating their | ||
| names, and connectors may ignore options they do not recognize. | ||
|
Comment on lines
+53
to
+59
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Two minor things here. First, consistency: #57724 documents this same Second, if the long form stays, it can lose some weight. The second sentence restates "for this statement only" from the first, and the last sentence makes the same point twice ("passes options through without validating their names" / "connectors may ignore options they do not recognize"). The backtick note is the part that really earns its place, since |
||
|
|
||
| * **SET column = value [ , ... ]** | ||
|
|
||
| Specifies the columns to update and the values to assign to them. Each `value` is an expression, | ||
| typically referencing columns of the target table, but it may also be `DEFAULT` or an | ||
| uncorrelated scalar subquery over another table. A comma separates each assignment. A nested | ||
| field may be targeted by using a qualified column name. | ||
|
|
||
| * **WHERE boolean_expression** | ||
|
|
||
| Specifies an optional condition that selects the rows to update. If the `WHERE` clause is | ||
| omitted, all rows are updated. | ||
|
|
||
| ### Examples | ||
|
|
||
| The following examples assume that an `employees` table has already been created and populated. | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The neighbouring DML pages make their examples runnable end to end. Here there is no schema for |
||
|
|
||
| #### Update Rows Matching a Condition | ||
|
|
||
| ```sql | ||
| UPDATE employees | ||
| SET salary = salary + 1000 | ||
| WHERE department = 'Engineering'; | ||
| ``` | ||
|
|
||
| #### Update Multiple Columns Using an Alias | ||
|
|
||
| ```sql | ||
| UPDATE employees AS e | ||
| SET e.salary = e.salary * 1.05, e.status = 'reviewed' | ||
| WHERE e.department = 'Sales'; | ||
|
Comment on lines
+88
to
+90
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Minor, and it mostly goes away once the example table has a stated schema: if |
||
| ``` | ||
|
|
||
| #### Update Using Dynamic Table Options | ||
|
|
||
| ```sql | ||
| -- Option names and values are specific to the table's data source connector. | ||
| UPDATE employees WITH (`write.split-size` = 10) | ||
| SET status = 'inactive' | ||
| WHERE last_active_date < DATE '2025-01-01'; | ||
| ``` | ||
|
|
||
| #### Update All Rows | ||
|
|
||
| ```sql | ||
| UPDATE employees SET status = 'active'; | ||
| ``` | ||
|
|
||
| ### Related Statements | ||
|
|
||
| * [DELETE FROM statement](sql-ref-syntax-dml-delete-from.html) | ||
| * [INSERT TABLE statement](sql-ref-syntax-dml-insert-table.html) | ||
| * [MERGE INTO statement](sql-ref-syntax-dml-merge-into.html) | ||
| * [SELECT statement](sql-ref-syntax-qry-select.html) | ||
|
Comment on lines
+108
to
+113
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For consistency, link to INSERT statement as well? |
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -48,9 +48,11 @@ Data Definition Statements are used to create or modify the structure of databas | |
|
|
||
| Data Manipulation Statements are used to add, change, or delete data. Spark SQL supports the following Data Manipulation Statements: | ||
|
|
||
| * [DELETE FROM](sql-ref-syntax-dml-delete-from.html) | ||
| * [INSERT TABLE](sql-ref-syntax-dml-insert-table.html) | ||
| * [INSERT OVERWRITE DIRECTORY](sql-ref-syntax-dml-insert-overwrite-directory.html) | ||
| * [MERGE INTO](sql-ref-syntax-dml-merge-into.html) | ||
| * [UPDATE](sql-ref-syntax-dml-update.html) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nit on placement. The DDL list above is strictly alphabetical, while this DML list is not ( |
||
| * [LOAD](sql-ref-syntax-dml-load.html) | ||
|
|
||
| ### Data Retrieval Statements | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same bullet as on the
UPDATEpage -- whatever wording you settle on there, please keep these two in sync (and ideally with theINSERT/MERGE INTO/SELECTpages in #57724).