Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/ast/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -654,14 +654,16 @@ impl fmt::Display for Values {
pub struct SelectInto {
pub temporary: bool,
pub unlogged: bool,
pub table: bool,
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like that this follows the rest of the crate's design to mirror the input syntax in the crated AST

👍

pub name: ObjectName,
}

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)
}
}
2 changes: 2 additions & 0 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 6 additions & 2 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -390,13 +390,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";
Expand Down