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
12 changes: 12 additions & 0 deletions crates/pgls_statement_splitter/src/splitter/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,18 @@ pub(crate) fn unknown(p: &mut Splitter, exclude: &[SyntaxKind]) -> SplitterResul
begin_end(p)?;
}
},
// When WITH_KW is excluded (e.g. inside CREATE) and followed by
// an identifier or RECURSIVE, it starts a CTE. Parse it as such
// so the following DML keyword is not treated as a new statement.
t if t == SyntaxKind::WITH_KW
&& exclude.contains(&SyntaxKind::WITH_KW)
&& matches!(
p.look_ahead(true),
SyntaxKind::IDENT | SyntaxKind::RECURSIVE_KW
) =>
{
cte(p)?;
}
t => match at_statement_start(t, exclude) {
Some(SyntaxKind::SELECT_KW) => {
let prev = p.look_back(true);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE TABLE foo (id int) WITH (fillfactor=70);
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
CREATE OR REPLACE VIEW profile_view AS WITH user_cte AS (SELECT * FROM accounts) SELECT * FROM user_cte;
Loading