mirror of
https://github.com/apache/datafusion-sqlparser-rs.git
synced 2025-11-11 19:43:47 +00:00
add SELECT INTO statement variation (#447)
Signed-off-by: Maciej Obuchowski <obuchowski.maciej@gmail.com>
This commit is contained in:
parent
b68e9a3801
commit
d38c30e9ff
7 changed files with 74 additions and 2 deletions
|
|
@ -36,8 +36,8 @@ pub use self::ddl::{
|
|||
pub use self::operator::{BinaryOperator, UnaryOperator};
|
||||
pub use self::query::{
|
||||
Cte, Fetch, Join, JoinConstraint, JoinOperator, LateralView, LockType, Offset, OffsetRows,
|
||||
OrderByExpr, Query, Select, SelectItem, SetExpr, SetOperator, TableAlias, TableFactor,
|
||||
TableWithJoins, Top, Values, With,
|
||||
OrderByExpr, Query, Select, SelectInto, SelectItem, SetExpr, SetOperator, TableAlias,
|
||||
TableFactor, TableWithJoins, Top, Values, With,
|
||||
};
|
||||
pub use self::value::{DateTimeField, TrimWhereField, Value};
|
||||
|
||||
|
|
|
|||
|
|
@ -136,6 +136,8 @@ pub struct Select {
|
|||
pub top: Option<Top>,
|
||||
/// projection expressions
|
||||
pub projection: Vec<SelectItem>,
|
||||
/// INTO
|
||||
pub into: Option<SelectInto>,
|
||||
/// FROM
|
||||
pub from: Vec<TableWithJoins>,
|
||||
/// LATERAL VIEWs
|
||||
|
|
@ -161,6 +163,11 @@ impl fmt::Display for Select {
|
|||
write!(f, " {}", top)?;
|
||||
}
|
||||
write!(f, " {}", display_comma_separated(&self.projection))?;
|
||||
|
||||
if let Some(ref into) = self.into {
|
||||
write!(f, " {}", into)?;
|
||||
}
|
||||
|
||||
if !self.from.is_empty() {
|
||||
write!(f, " FROM {}", display_comma_separated(&self.from))?;
|
||||
}
|
||||
|
|
@ -636,3 +643,20 @@ impl fmt::Display for Values {
|
|||
Ok(())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
|
||||
#[cfg_attr(feature = "serde", derive(Serialize, Deserialize))]
|
||||
pub struct SelectInto {
|
||||
pub temporary: bool,
|
||||
pub unlogged: bool,
|
||||
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 { "" };
|
||||
|
||||
write!(f, "INTO{}{} {}", temporary, unlogged, self.name)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -499,6 +499,7 @@ define_keywords!(
|
|||
UNION,
|
||||
UNIQUE,
|
||||
UNKNOWN,
|
||||
UNLOGGED,
|
||||
UNNEST,
|
||||
UNSIGNED,
|
||||
UPDATE,
|
||||
|
|
@ -600,4 +601,5 @@ pub const RESERVED_FOR_COLUMN_ALIAS: &[Keyword] = &[
|
|||
Keyword::DISTRIBUTE,
|
||||
// Reserved only as a column alias in the `SELECT` clause
|
||||
Keyword::FROM,
|
||||
Keyword::INTO,
|
||||
];
|
||||
|
|
|
|||
|
|
@ -2892,6 +2892,21 @@ impl<'a> Parser<'a> {
|
|||
|
||||
let projection = self.parse_comma_separated(Parser::parse_select_item)?;
|
||||
|
||||
let into = if self.parse_keyword(Keyword::INTO) {
|
||||
let temporary = self
|
||||
.parse_one_of_keywords(&[Keyword::TEMP, Keyword::TEMPORARY])
|
||||
.is_some();
|
||||
let unlogged = self.parse_keyword(Keyword::UNLOGGED);
|
||||
let name = self.parse_object_name()?;
|
||||
Some(SelectInto {
|
||||
temporary,
|
||||
unlogged,
|
||||
name,
|
||||
})
|
||||
} else {
|
||||
None
|
||||
};
|
||||
|
||||
// Note that for keywords to be properly handled here, they need to be
|
||||
// added to `RESERVED_FOR_COLUMN_ALIAS` / `RESERVED_FOR_TABLE_ALIAS`,
|
||||
// otherwise they may be parsed as an alias as part of the `projection`
|
||||
|
|
@ -2973,6 +2988,7 @@ impl<'a> Parser<'a> {
|
|||
distinct,
|
||||
top,
|
||||
projection,
|
||||
into,
|
||||
from,
|
||||
lateral_views,
|
||||
selection,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue