From 6b2fc8102f39ae92273b9ef9ace1285f6145b546 Mon Sep 17 00:00:00 2001 From: Alex Qyoun-ae <4062971+MazterQyou@users.noreply.github.com> Date: Mon, 9 May 2022 22:29:43 +0400 Subject: [PATCH] feat: Support `TABLE` keyword with `SELECT INTO` (#487) --- src/ast/query.rs | 4 +++- src/parser.rs | 2 ++ tests/sqlparser_common.rs | 8 ++++++-- 3 files changed, 11 insertions(+), 3 deletions(-) diff --git a/src/ast/query.rs b/src/ast/query.rs index 7526c23c..472b9e6b 100644 --- a/src/ast/query.rs +++ b/src/ast/query.rs @@ -654,6 +654,7 @@ impl fmt::Display for Values { pub struct SelectInto { pub temporary: bool, pub unlogged: bool, + pub table: bool, pub name: ObjectName, } @@ -661,7 +662,8 @@ impl fmt::Display for SelectInto { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { let temporary = if self.temporary { " TEMPORARY" } else { "" }; let unlogged = if self.unlogged { " UNLOGGED" } else { "" }; + let table = if self.table { " TABLE" } else { "" }; - write!(f, "INTO{}{} {}", temporary, unlogged, self.name) + write!(f, "INTO{}{}{} {}", temporary, unlogged, table, self.name) } } diff --git a/src/parser.rs b/src/parser.rs index c67ce9a5..e7f2e24b 100644 --- a/src/parser.rs +++ b/src/parser.rs @@ -3138,10 +3138,12 @@ impl<'a> Parser<'a> { .parse_one_of_keywords(&[Keyword::TEMP, Keyword::TEMPORARY]) .is_some(); let unlogged = self.parse_keyword(Keyword::UNLOGGED); + let table = self.parse_keyword(Keyword::TABLE); let name = self.parse_object_name()?; Some(SelectInto { temporary, unlogged, + table, name, }) } else { diff --git a/tests/sqlparser_common.rs b/tests/sqlparser_common.rs index fcc30b31..b70f592f 100644 --- a/tests/sqlparser_common.rs +++ b/tests/sqlparser_common.rs @@ -383,13 +383,17 @@ fn parse_select_into() { &SelectInto { temporary: false, unlogged: false, + table: false, name: ObjectName(vec![Ident::new("table0")]) }, only(&select.into) ); - let sql = "SELECT * INTO TEMPORARY UNLOGGED table0 FROM table1"; - one_statement_parses_to(sql, "SELECT * INTO TEMPORARY UNLOGGED table0 FROM table1"); + let sql = "SELECT * INTO TEMPORARY UNLOGGED TABLE table0 FROM table1"; + one_statement_parses_to( + sql, + "SELECT * INTO TEMPORARY UNLOGGED TABLE table0 FROM table1", + ); // Do not allow aliases here let sql = "SELECT * INTO table0 asdf FROM table1";