From d59b6638fad907886c5a4dabc63680afb47da46e Mon Sep 17 00:00:00 2001 From: Ophir LOJKINE Date: Mon, 12 Feb 2024 22:44:22 +0100 Subject: [PATCH] add support for `insert into ... select ... returning ...` (#1132) --- src/keywords.rs | 1 + tests/sqlparser_common.rs | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/src/keywords.rs b/src/keywords.rs index 771e8670..ec9d4251 100644 --- a/src/keywords.rs +++ b/src/keywords.rs @@ -810,6 +810,7 @@ pub const RESERVED_FOR_COLUMN_ALIAS: &[Keyword] = &[ Keyword::INTERSECT, Keyword::CLUSTER, Keyword::DISTRIBUTE, + Keyword::RETURNING, // Reserved only as a column alias in the `SELECT` clause Keyword::FROM, Keyword::INTO, diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs index 21cbcc99..bd95e316 100644 --- a/tests/sqlparser_common.rs +++ b/tests/sqlparser_common.rs @@ -225,6 +225,25 @@ fn parse_insert_default_values() { ); } +#[test] +fn parse_insert_select_returning() { + verified_stmt("INSERT INTO t SELECT 1 RETURNING 2"); + let stmt = verified_stmt("INSERT INTO t SELECT x RETURNING x AS y"); + match stmt { + Statement::Insert { + returning: Some(ret), + source: Some(_), + .. + } => assert_eq!(ret.len(), 1), + _ => unreachable!(), + } +} + +#[test] +fn parse_returning_as_column_alias() { + verified_stmt("SELECT 1 AS RETURNING"); +} + #[test] fn parse_insert_sqlite() { let dialect = SQLiteDialect {};