mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-07-07 17:04:59 +00:00
fix parsing of INSERT INTO ... SELECT ... RETURNING
(#1661)
This commit is contained in:
parent
b4b5576dd4
commit
3eeb9160ea
2 changed files with 22 additions and 0 deletions
|
@ -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,
|
||||
|
|
|
@ -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");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue