Skip to content

fix parsing of INSERT INTO ... SELECT ... RETURNING #1661

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 17, 2025
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