Skip to content

Commit 501697b

Browse files
lovasoaDenys Tsomenko
authored and
Denys Tsomenko
committed
fix parsing of INSERT INTO ... SELECT ... RETURNING (apache#1661)
1 parent 69f401a commit 501697b

File tree

2 files changed

+22
-0
lines changed

2 files changed

+22
-0
lines changed

src/keywords.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -954,6 +954,7 @@ pub const RESERVED_FOR_TABLE_ALIAS: &[Keyword] = &[
954954
Keyword::GLOBAL,
955955
Keyword::ANTI,
956956
Keyword::SEMI,
957+
Keyword::RETURNING,
957958
// for MSSQL-specific OUTER APPLY (seems reserved in most dialects)
958959
Keyword::OUTER,
959960
Keyword::SET,

tests/sqlparser_common.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,27 @@ fn parse_insert_select_returning() {
265265
}
266266
}
267267

268+
#[test]
269+
fn parse_insert_select_from_returning() {
270+
let sql = "INSERT INTO table1 SELECT * FROM table2 RETURNING id";
271+
match verified_stmt(sql) {
272+
Statement::Insert(Insert {
273+
table: TableObject::TableName(table_name),
274+
source: Some(source),
275+
returning: Some(returning),
276+
..
277+
}) => {
278+
assert_eq!("table1", table_name.to_string());
279+
assert!(matches!(*source.body, SetExpr::Select(_)));
280+
assert_eq!(
281+
returning,
282+
vec![SelectItem::UnnamedExpr(Expr::Identifier(Ident::new("id"))),]
283+
);
284+
}
285+
bad_stmt => unreachable!("Expected valid insert, got {:?}", bad_stmt),
286+
}
287+
}
288+
268289
#[test]
269290
fn parse_returning_as_column_alias() {
270291
verified_stmt("SELECT 1 AS RETURNING");

0 commit comments

Comments
 (0)