Skip to content

Commit d59b663

Browse files
authored
add support for insert into ... select ... returning ... (apache#1132)
1 parent a5ac425 commit d59b663

2 files changed

Lines changed: 20 additions & 0 deletions

File tree

src/keywords.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -810,6 +810,7 @@ pub const RESERVED_FOR_COLUMN_ALIAS: &[Keyword] = &[
810810
Keyword::INTERSECT,
811811
Keyword::CLUSTER,
812812
Keyword::DISTRIBUTE,
813+
Keyword::RETURNING,
813814
// Reserved only as a column alias in the `SELECT` clause
814815
Keyword::FROM,
815816
Keyword::INTO,

tests/sqlparser_common.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,25 @@ fn parse_insert_default_values() {
225225
);
226226
}
227227

228+
#[test]
229+
fn parse_insert_select_returning() {
230+
verified_stmt("INSERT INTO t SELECT 1 RETURNING 2");
231+
let stmt = verified_stmt("INSERT INTO t SELECT x RETURNING x AS y");
232+
match stmt {
233+
Statement::Insert {
234+
returning: Some(ret),
235+
source: Some(_),
236+
..
237+
} => assert_eq!(ret.len(), 1),
238+
_ => unreachable!(),
239+
}
240+
}
241+
242+
#[test]
243+
fn parse_returning_as_column_alias() {
244+
verified_stmt("SELECT 1 AS RETURNING");
245+
}
246+
228247
#[test]
229248
fn parse_insert_sqlite() {
230249
let dialect = SQLiteDialect {};

0 commit comments

Comments
 (0)