Skip to content

Commit

Permalink
fix parsing of INSERT INTO ... SELECT ... RETURNING (#1661)
Browse files Browse the repository at this point in the history
  • Loading branch information
lovasoa authored Jan 17, 2025
1 parent b4b5576 commit 3eeb916
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
1 change: 1 addition & 0 deletions src/keywords.rs
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,7 @@ pub const RESERVED_FOR_TABLE_ALIAS: &[Keyword] = &[
Keyword::GLOBAL,
Keyword::ANTI,
Keyword::SEMI,
Keyword::RETURNING,
// for MSSQL-specific OUTER APPLY (seems reserved in most dialects)
Keyword::OUTER,
Keyword::SET,
Expand Down
21 changes: 21 additions & 0 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,27 @@ fn parse_insert_select_returning() {
}
}

#[test]
fn parse_insert_select_from_returning() {
let sql = "INSERT INTO table1 SELECT * FROM table2 RETURNING id";
match verified_stmt(sql) {
Statement::Insert(Insert {
table: TableObject::TableName(table_name),
source: Some(source),
returning: Some(returning),
..
}) => {
assert_eq!("table1", table_name.to_string());
assert!(matches!(*source.body, SetExpr::Select(_)));
assert_eq!(
returning,
vec![SelectItem::UnnamedExpr(Expr::Identifier(Ident::new("id"))),]
);
}
bad_stmt => unreachable!("Expected valid insert, got {:?}", bad_stmt),
}
}

#[test]
fn parse_returning_as_column_alias() {
verified_stmt("SELECT 1 AS RETURNING");
Expand Down

0 comments on commit 3eeb916

Please sign in to comment.