Skip to content

Commit a1fdb5b

Browse files
fix: parse unions (#329)
1 parent 4867189 commit a1fdb5b

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

crates/pgt_statement_splitter/src/parser.rs

+2
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ impl Parser {
147147
}
148148

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

165+
/// Returns `None` if there are no previous relevant tokens
164166
fn look_back(&self) -> Option<&Token> {
165167
// we need to look back to the last relevant token
166168
let mut look_back_pos = self.next_pos - 1;

crates/pgt_statement_splitter/src/parser/common.rs

+6
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,12 @@ pub(crate) fn unknown(p: &mut Parser, exclude: &[SyntaxKind]) {
145145
SyntaxKind::Also,
146146
// for create rule
147147
SyntaxKind::Instead,
148+
// for UNION
149+
SyntaxKind::Union,
150+
// for UNION ALL
151+
SyntaxKind::All,
152+
// for UNION ... EXCEPT
153+
SyntaxKind::Except,
148154
]
149155
.iter()
150156
.all(|x| Some(x) != prev.as_ref())
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
select 1 union all select 2;
2+
3+
select 1 union select 2;
4+
5+
select 1 union select 2 except select 3;
6+
7+
select 1 union all select 2 except select 3;

0 commit comments

Comments
 (0)