Skip to content

fix: parse unions #329

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 12, 2025
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
2 changes: 2 additions & 0 deletions crates/pgt_statement_splitter/src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,7 @@ impl Parser {
}

/// Look ahead to the next relevant token
/// Returns `None` if we are already at the last relevant token
fn look_ahead(&self) -> Option<&Token> {
// we need to look ahead to the next relevant token
let mut look_ahead_pos = self.next_pos + 1;
Expand All @@ -161,6 +162,7 @@ impl Parser {
}
}

/// Returns `None` if there are no previous relevant tokens
fn look_back(&self) -> Option<&Token> {
// we need to look back to the last relevant token
let mut look_back_pos = self.next_pos - 1;
Expand Down
6 changes: 6 additions & 0 deletions crates/pgt_statement_splitter/src/parser/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,12 @@ pub(crate) fn unknown(p: &mut Parser, exclude: &[SyntaxKind]) {
SyntaxKind::Also,
// for create rule
SyntaxKind::Instead,
// for UNION
SyntaxKind::Union,
// for UNION ALL
SyntaxKind::All,
// for UNION ... EXCEPT
SyntaxKind::Except,
]
.iter()
.all(|x| Some(x) != prev.as_ref())
Expand Down
7 changes: 7 additions & 0 deletions crates/pgt_statement_splitter/tests/data/simple_union__4.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
select 1 union all select 2;

select 1 union select 2;

select 1 union select 2 except select 3;

select 1 union all select 2 except select 3;