Skip to content

Commit 6b2fc81

Browse files
authored
feat: Support TABLE keyword with SELECT INTO (#487)
1 parent 6d057ef commit 6b2fc81

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
@@ -654,14 +654,16 @@ impl fmt::Display for Values {
654654
pub struct SelectInto {
655655
pub temporary: bool,
656656
pub unlogged: bool,
657+
pub table: bool,
657658
pub name: ObjectName,
658659
}
659660

660661
impl fmt::Display for SelectInto {
661662
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
662663
let temporary = if self.temporary { " TEMPORARY" } else { "" };
663664
let unlogged = if self.unlogged { " UNLOGGED" } else { "" };
665+
let table = if self.table { " TABLE" } else { "" };
664666

665-
write!(f, "INTO{}{} {}", temporary, unlogged, self.name)
667+
write!(f, "INTO{}{}{} {}", temporary, unlogged, table, self.name)
666668
}
667669
}

src/parser.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3138,10 +3138,12 @@ impl<'a> Parser<'a> {
31383138
.parse_one_of_keywords(&[Keyword::TEMP, Keyword::TEMPORARY])
31393139
.is_some();
31403140
let unlogged = self.parse_keyword(Keyword::UNLOGGED);
3141+
let table = self.parse_keyword(Keyword::TABLE);
31413142
let name = self.parse_object_name()?;
31423143
Some(SelectInto {
31433144
temporary,
31443145
unlogged,
3146+
table,
31453147
name,
31463148
})
31473149
} else {

tests/sqlparser_common.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -383,13 +383,17 @@ fn parse_select_into() {
383383
&SelectInto {
384384
temporary: false,
385385
unlogged: false,
386+
table: false,
386387
name: ObjectName(vec![Ident::new("table0")])
387388
},
388389
only(&select.into)
389390
);
390391

391-
let sql = "SELECT * INTO TEMPORARY UNLOGGED table0 FROM table1";
392-
one_statement_parses_to(sql, "SELECT * INTO TEMPORARY UNLOGGED table0 FROM table1");
392+
let sql = "SELECT * INTO TEMPORARY UNLOGGED TABLE table0 FROM table1";
393+
one_statement_parses_to(
394+
sql,
395+
"SELECT * INTO TEMPORARY UNLOGGED TABLE table0 FROM table1",
396+
);
393397

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

0 commit comments

Comments
 (0)