Skip to content
Open
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
8 changes: 4 additions & 4 deletions src/ast/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6631,7 +6631,7 @@ pub struct TruncateTableTarget {
/// TRUNCATE TABLE name [ * ]
/// ```
/// <https://www.postgresql.org/docs/current/sql-truncate.html>
pub has_asterisk: bool,
pub has_trailing_asterisk: bool,
}

impl fmt::Display for TruncateTableTarget {
Expand All @@ -6640,7 +6640,7 @@ impl fmt::Display for TruncateTableTarget {
write!(f, "ONLY ")?;
};
write!(f, "{}", self.name)?;
if self.has_asterisk {
if self.has_trailing_asterisk {
write!(f, " *")?;
};
Ok(())
Expand Down Expand Up @@ -6688,7 +6688,7 @@ pub struct LockTableTarget {
/// Whether `ONLY` was specified to exclude descendant tables.
pub only: bool,
/// Whether `*` was specified to explicitly include descendant tables.
pub has_asterisk: bool,
pub has_trailing_asterisk: bool,
}

impl fmt::Display for LockTableTarget {
Expand All @@ -6697,7 +6697,7 @@ impl fmt::Display for LockTableTarget {
write!(f, "ONLY ")?;
}
write!(f, "{}", self.name)?;
if self.has_asterisk {
if self.has_trailing_asterisk {
write!(f, " *")?;
}
Ok(())
Expand Down
8 changes: 8 additions & 0 deletions src/ast/query.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1494,6 +1494,10 @@ pub enum TableFactor {
/// Optional index hints(mysql)
/// See: <https://dev.mysql.com/doc/refman/8.4/en/index-hints.html>
index_hints: Vec<TableIndexHints>,
/// Whether a trailing `*` was specified, e.g. `FROM tab*`, to explicitly
/// include descendant tables, as supported by
/// [Postgres](https://www.postgresql.org/docs/current/sql-select.html#SQL-FROM).
has_trailing_asterisk: bool,
},
/// A derived table (a parenthesized subquery), optionally `LATERAL`.
Derived {
Expand Down Expand Up @@ -2225,11 +2229,15 @@ impl fmt::Display for TableFactor {
json_path,
sample,
index_hints,
has_trailing_asterisk,
} => {
name.fmt(f)?;
if let Some(json_path) = json_path {
json_path.fmt(f)?;
}
if *has_trailing_asterisk {
write!(f, "*")?;
}
if !partitions.is_empty() {
write!(f, " PARTITION ({})", display_comma_separated(partitions))?;
}
Expand Down
1 change: 1 addition & 0 deletions src/ast/spans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1979,6 +1979,7 @@ impl Spanned for TableFactor {
json_path: _,
sample: _,
index_hints: _,
has_trailing_asterisk: _,
} => union_spans(
name.0
.iter()
Expand Down
14 changes: 10 additions & 4 deletions src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1121,11 +1121,11 @@ impl<'a> Parser<'a> {
let table_names = self.parse_comma_separated(|p| {
let only = p.parse_keyword(Keyword::ONLY);
let name = p.parse_object_name(false)?;
let has_asterisk = p.consume_token(&Token::Mul);
let has_trailing_asterisk = p.consume_token(&Token::Mul);
Ok(TruncateTableTarget {
name,
only,
has_asterisk,
has_trailing_asterisk,
})
})?;

Expand Down Expand Up @@ -16748,6 +16748,10 @@ impl<'a> Parser<'a> {
} else {
let name = self.parse_object_name(true)?;

// Postgres/Snowflake: `FROM tab*` explicitly includes descendant tables.
// https://www.postgresql.org/docs/current/sql-select.html#SQL-FROM
let has_trailing_asterisk = self.consume_token(&Token::Mul);

let json_path = match &self.peek_token_ref().token {
Token::LBracket if self.dialect.supports_partiql() => Some(self.parse_json_path()?),
_ => None,
Expand Down Expand Up @@ -16819,6 +16823,7 @@ impl<'a> Parser<'a> {
json_path,
sample,
index_hints,
has_trailing_asterisk,
};

while let Some(kw) = self.parse_one_of_keywords(&[Keyword::PIVOT, Keyword::UNPIVOT]) {
Expand Down Expand Up @@ -16869,6 +16874,7 @@ impl<'a> Parser<'a> {
json_path: None,
sample: None,
index_hints: vec![],
has_trailing_asterisk: false,
})
}

Expand Down Expand Up @@ -19707,12 +19713,12 @@ impl<'a> Parser<'a> {
fn parse_lock_table_target(&mut self) -> Result<LockTableTarget, ParserError> {
let only = self.parse_keyword(Keyword::ONLY);
let name = self.parse_object_name(false)?;
let has_asterisk = self.consume_token(&Token::Mul);
let has_trailing_asterisk = self.consume_token(&Token::Mul);

Ok(LockTableTarget {
name,
only,
has_asterisk,
has_trailing_asterisk,
})
}

Expand Down
3 changes: 3 additions & 0 deletions src/test_utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -391,6 +391,7 @@ pub fn table(name: impl Into<String>) -> TableFactor {
json_path: None,
sample: None,
index_hints: vec![],
has_trailing_asterisk: false,
}
}

Expand All @@ -406,6 +407,7 @@ pub fn table_from_name(name: ObjectName) -> TableFactor {
json_path: None,
sample: None,
index_hints: vec![],
has_trailing_asterisk: false,
}
}

Expand All @@ -425,6 +427,7 @@ pub fn table_with_alias(
json_path: None,
sample: None,
index_hints: vec![],
has_trailing_asterisk: false,
}
}

Expand Down
3 changes: 3 additions & 0 deletions tests/sqlparser_bigquery.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1756,6 +1756,7 @@ fn parse_table_time_travel() {
json_path: None,
sample: None,
index_hints: vec![],
has_trailing_asterisk: false,
},
joins: vec![]
},]
Expand Down Expand Up @@ -1866,6 +1867,7 @@ fn parse_merge() {
json_path: None,
sample: None,
index_hints: vec![],
has_trailing_asterisk: false,
},
table
);
Expand All @@ -1881,6 +1883,7 @@ fn parse_merge() {
json_path: None,
sample: None,
index_hints: vec![],
has_trailing_asterisk: false,
},
source
);
Expand Down
27 changes: 25 additions & 2 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,7 @@ fn parse_update_with_table_alias() {
json_path: None,
sample: None,
index_hints: vec![],
has_trailing_asterisk: false,
},
joins: vec![],
},
Expand Down Expand Up @@ -702,6 +703,7 @@ fn parse_select_with_table_alias() {
json_path: None,
sample: None,
index_hints: vec![],
has_trailing_asterisk: false,
},
joins: vec![],
}]
Expand Down Expand Up @@ -900,6 +902,7 @@ fn parse_where_delete_with_alias_statement() {
json_path: None,
sample: None,
index_hints: vec![],
has_trailing_asterisk: false,
},
from[0].relation,
);
Expand All @@ -916,6 +919,7 @@ fn parse_where_delete_with_alias_statement() {
json_path: None,
sample: None,
index_hints: vec![],
has_trailing_asterisk: false,
},
joins: vec![],
}]),
Expand Down Expand Up @@ -7756,6 +7760,7 @@ fn parse_joins_on() {
json_path: None,
sample: None,
index_hints: vec![],
has_trailing_asterisk: false,
},
global,
join_operator: f(JoinConstraint::On(Expr::BinaryOp {
Expand Down Expand Up @@ -7898,6 +7903,7 @@ fn parse_joins_using() {
json_path: None,
sample: None,
index_hints: vec![],
has_trailing_asterisk: false,
},
global: false,
join_operator: f(JoinConstraint::Using(vec![ObjectName::from(vec![
Expand Down Expand Up @@ -7993,6 +7999,7 @@ fn parse_natural_join() {
json_path: None,
sample: None,
index_hints: vec![],
has_trailing_asterisk: false,
},
global: false,
join_operator: f(JoinConstraint::Natural),
Expand Down Expand Up @@ -10431,6 +10438,7 @@ fn parse_merge() {
json_path: None,
sample: None,
index_hints: vec![],
has_trailing_asterisk: false,
}
);
assert_eq!(table, table_no_into);
Expand Down Expand Up @@ -11867,6 +11875,7 @@ fn parse_pivot_table() {
json_path: None,
sample: None,
index_hints: vec![],
has_trailing_asterisk: false,
}),
aggregate_functions: vec![
expected_function("a", None),
Expand Down Expand Up @@ -11947,6 +11956,7 @@ fn parse_pivot_table() {
json_path: None,
sample: None,
index_hints: vec![],
has_trailing_asterisk: false,
}),
aggregate_functions: vec![
ExprWithAlias {
Expand Down Expand Up @@ -12026,6 +12036,7 @@ fn parse_unpivot_table() {
json_path: None,
sample: None,
index_hints: vec![],
has_trailing_asterisk: false,
}),
null_inclusion: None,
value: Expr::Identifier(Ident::new("quantity")),
Expand Down Expand Up @@ -12282,6 +12293,7 @@ fn parse_select_table_with_index_hints() {
json_path: None,
sample: None,
index_hints: vec![],
has_trailing_asterisk: false,
},
joins: vec![],
}]
Expand Down Expand Up @@ -12311,6 +12323,7 @@ fn parse_pivot_unpivot_table() {
json_path: None,
sample: None,
index_hints: vec![],
has_trailing_asterisk: false,
}),
null_inclusion: None,
value: Expr::Identifier(Ident::new("population")),
Expand Down Expand Up @@ -17807,12 +17820,12 @@ fn parse_truncate_only() {
TruncateTableTarget {
name: ObjectName::from(vec![Ident::new("employee")]),
only: false,
has_asterisk: false,
has_trailing_asterisk: false,
},
TruncateTableTarget {
name: ObjectName::from(vec![Ident::new("dept")]),
only: true,
has_asterisk: false,
has_trailing_asterisk: false,
},
];

Expand Down Expand Up @@ -17896,6 +17909,7 @@ fn test_nested_join_without_parentheses() {
json_path: None,
sample: None,
index_hints: vec![],
has_trailing_asterisk: false,
},
joins: vec![Join {
relation: TableFactor::Table {
Expand All @@ -17909,6 +17923,7 @@ fn test_nested_join_without_parentheses() {
json_path: None,
sample: None,
index_hints: vec![],
has_trailing_asterisk: false,
},
global: false,
join_operator: JoinOperator::Inner(JoinConstraint::On(Expr::BinaryOp {
Expand Down Expand Up @@ -17963,6 +17978,7 @@ fn test_nested_join_without_parentheses() {
json_path: None,
sample: None,
index_hints: vec![],
has_trailing_asterisk: false,
},
joins: vec![Join {
relation: TableFactor::Table {
Expand All @@ -17976,6 +17992,7 @@ fn test_nested_join_without_parentheses() {
json_path: None,
sample: None,
index_hints: vec![],
has_trailing_asterisk: false,
},
global: false,
join_operator: JoinOperator::Join(JoinConstraint::On(Expr::BinaryOp {
Expand Down Expand Up @@ -18030,6 +18047,7 @@ fn test_nested_join_without_parentheses() {
json_path: None,
sample: None,
index_hints: vec![],
has_trailing_asterisk: false,
},
joins: vec![Join {
relation: TableFactor::Table {
Expand All @@ -18043,6 +18061,7 @@ fn test_nested_join_without_parentheses() {
json_path: None,
sample: None,
index_hints: vec![],
has_trailing_asterisk: false,
},
global: false,
join_operator: JoinOperator::Left(JoinConstraint::On(Expr::BinaryOp {
Expand Down Expand Up @@ -18097,6 +18116,7 @@ fn test_nested_join_without_parentheses() {
json_path: None,
sample: None,
index_hints: vec![],
has_trailing_asterisk: false,
},
joins: vec![Join {
relation: TableFactor::Table {
Expand All @@ -18110,6 +18130,7 @@ fn test_nested_join_without_parentheses() {
json_path: None,
sample: None,
index_hints: vec![],
has_trailing_asterisk: false,
},
global: false,
join_operator: JoinOperator::Right(JoinConstraint::On(Expr::BinaryOp {
Expand Down Expand Up @@ -18164,6 +18185,7 @@ fn test_nested_join_without_parentheses() {
json_path: None,
sample: None,
index_hints: vec![],
has_trailing_asterisk: false,
},
joins: vec![Join {
relation: TableFactor::Table {
Expand All @@ -18177,6 +18199,7 @@ fn test_nested_join_without_parentheses() {
json_path: None,
sample: None,
index_hints: vec![],
has_trailing_asterisk: false,
},
global: false,
join_operator: JoinOperator::FullOuter(JoinConstraint::On(
Expand Down
1 change: 1 addition & 0 deletions tests/sqlparser_hive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -472,6 +472,7 @@ fn parse_delimited_identifiers() {
json_path: _,
sample: _,
index_hints: _,
has_trailing_asterisk: _,
} => {
assert_eq!(
ObjectName::from(vec![Ident::with_quote('"', "a table")]),
Expand Down
Loading
Loading