Skip to content

Commit 81217ce

Browse files
committed
feat: Support TABLE keyword with SELECT INTO (apache#487)
1 parent 91599e8 commit 81217ce

File tree

3 files changed

+11
-3
lines changed

3 files changed

+11
-3
lines changed

src/ast/query.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -649,14 +649,16 @@ impl fmt::Display for Values {
649649
pub struct SelectInto {
650650
pub temporary: bool,
651651
pub unlogged: bool,
652+
pub table: bool,
652653
pub name: ObjectName,
653654
}
654655

655656
impl fmt::Display for SelectInto {
656657
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
657658
let temporary = if self.temporary { " TEMPORARY" } else { "" };
658659
let unlogged = if self.unlogged { " UNLOGGED" } else { "" };
660+
let table = if self.table { " TABLE" } else { "" };
659661

660-
write!(f, "INTO{}{} {}", temporary, unlogged, self.name)
662+
write!(f, "INTO{}{}{} {}", temporary, unlogged, table, self.name)
661663
}
662664
}

src/parser.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3066,10 +3066,12 @@ impl<'a> Parser<'a> {
30663066
.parse_one_of_keywords(&[Keyword::TEMP, Keyword::TEMPORARY])
30673067
.is_some();
30683068
let unlogged = self.parse_keyword(Keyword::UNLOGGED);
3069+
let table = self.parse_keyword(Keyword::TABLE);
30693070
let name = self.parse_object_name()?;
30703071
Some(SelectInto {
30713072
temporary,
30723073
unlogged,
3074+
table,
30733075
name,
30743076
})
30753077
} else {

tests/sqlparser_common.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -390,13 +390,17 @@ fn parse_select_into() {
390390
&SelectInto {
391391
temporary: false,
392392
unlogged: false,
393+
table: false,
393394
name: ObjectName(vec![Ident::new("table0")])
394395
},
395396
only(&select.into)
396397
);
397398

398-
let sql = "SELECT * INTO TEMPORARY UNLOGGED table0 FROM table1";
399-
one_statement_parses_to(sql, "SELECT * INTO TEMPORARY UNLOGGED table0 FROM table1");
399+
let sql = "SELECT * INTO TEMPORARY UNLOGGED TABLE table0 FROM table1";
400+
one_statement_parses_to(
401+
sql,
402+
"SELECT * INTO TEMPORARY UNLOGGED TABLE table0 FROM table1",
403+
);
400404

401405
// Do not allow aliases here
402406
let sql = "SELECT * INTO table0 asdf FROM table1";

0 commit comments

Comments
 (0)