Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading