This is an automated email from the ASF dual-hosted git repository.

yao pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/spark.git


The following commit(s) were added to refs/heads/master by this push:
     new fd8436ae785 [SPARK-44869][DOC] Add doc for insert by name statement
fd8436ae785 is described below

commit fd8436ae785ac91373624d0ef46d94b85dcc094f
Author: Jia Fan <fanjiaemi...@qq.com>
AuthorDate: Sat Aug 19 01:14:34 2023 +0800

    [SPARK-44869][DOC] Add doc for insert by name statement
    
    ### What changes were proposed in this pull request?
    Add `INSERT BY NAME` statement to the document.
    
    ### Why are the changes needed?
    Add `INSERT BY NAME` to the doc, so user can easy to know this feature.
    
    ### Does this PR introduce _any_ user-facing change?
    No
    
    ### How was this patch tested?
    unnecessary.
    
    Closes #42558 from Hisoka-X/SPARK-44869_insert_by_name_doc.
    
    Authored-by: Jia Fan <fanjiaemi...@qq.com>
    Signed-off-by: Kent Yao <y...@apache.org>
---
 docs/sql-ref-syntax-dml-insert-table.md | 42 ++++++++++++++++++++++++++++++++-
 1 file changed, 41 insertions(+), 1 deletion(-)

diff --git a/docs/sql-ref-syntax-dml-insert-table.md 
b/docs/sql-ref-syntax-dml-insert-table.md
index ea8a2789cae..6ca062e0817 100644
--- a/docs/sql-ref-syntax-dml-insert-table.md
+++ b/docs/sql-ref-syntax-dml-insert-table.md
@@ -26,7 +26,7 @@ The `INSERT` statement inserts new rows into a table or 
overwrites the existing
 ### Syntax
 
 ```sql
-INSERT [ INTO | OVERWRITE ] [ TABLE ] table_identifier [ partition_spec ] [ ( 
column_list ) ]
+INSERT [ INTO | OVERWRITE ] [ TABLE ] table_identifier [ partition_spec ] [ ( 
column_list ) | [BY NAME] ]
     { VALUES ( { value | NULL } [ , ... ] ) [ , ( ... ) ] | query }
 
 INSERT INTO [ TABLE ] table_identifier REPLACE WHERE boolean_expression query
@@ -318,6 +318,46 @@ SELECT * FROM students;
 +-------------+--------------------------+----------+
 ```
 
+##### Insert By Name Using a SELECT Statement
+
+```sql
+-- Assuming the persons table has already been created and populated.
+SELECT * FROM persons;
++-------------+--------------------------+---------+
+|         name|                   address|      ssn|
++-------------+--------------------------+---------+
+|Dora Williams|134 Forest Ave, Menlo Park|123456789|
++-------------+--------------------------+---------+
+|  Eddie Davis|   245 Market St, Milpitas|345678901|
++-------------+--------------------------+---------+
+
+-- Spark will reorder the fields of the query according to the order of the 
fields in the table,
+-- so don't worry about the field order mismatch
+INSERT INTO students PARTITION (student_id = 222222) BY NAME
+    SELECT address, name FROM persons WHERE name = "Dora Williams";
+
+SELECT * FROM students;
++-------------+--------------------------+----------+
+|         name|                   address|student_id|
++-------------+--------------------------+----------+
+|   Ashua Hill|   456 Erica Ct, Cupertino|    111111|
++-------------+--------------------------+----------+
+|Dora Williams|134 Forest Ave, Menlo Park|    222222|
++-------------+--------------------------+----------+
+    
+INSERT OVERWRITE students PARTITION (student_id = 222222) BY NAME
+    SELECT 'Unknown' as address, name FROM persons WHERE name = "Dora 
Williams";
+
+SELECT * FROM students;
++-------------+--------------------------+----------+
+|         name|                   address|student_id|
++-------------+--------------------------+----------+
+|   Ashua Hill|   456 Erica Ct, Cupertino|    111111|
++-------------+--------------------------+----------+
+|Dora Williams|                   Unknown|    222222|
++-------------+--------------------------+----------+
+```
+
 ##### Insert Using a REPLACE WHERE Statement
 
 ```sql


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@spark.apache.org
For additional commands, e-mail: commits-h...@spark.apache.org

Reply via email to