Skip to content
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
27 changes: 27 additions & 0 deletions crates/pgls_statement_splitter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -607,4 +607,31 @@ VALUES
// does not panic
let _ = Tester::from("select case ");
}

#[test]
fn with_cte_as_materialized() {
Tester::from(
"WITH latest AS MATERIALIZED (SELECT id FROM submissions) SELECT * FROM latest;",
)
.assert_single_statement()
.assert_no_errors();
}

#[test]
fn with_cte_as_not_materialized() {
Tester::from(
"WITH latest AS NOT MATERIALIZED (SELECT id FROM submissions) SELECT * FROM latest;",
)
.assert_single_statement()
.assert_no_errors();
}

#[test]
fn with_multiple_materialized_ctes() {
Tester::from(
"WITH a AS (SELECT 1), b AS MATERIALIZED (SELECT 2), c AS NOT MATERIALIZED (SELECT 3) SELECT * FROM a, b, c;",
)
.assert_single_statement()
.assert_no_errors();
}
}
3 changes: 3 additions & 0 deletions crates/pgls_statement_splitter/src/splitter/dml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ pub(crate) fn cte(p: &mut Splitter) -> SplitterResult {
loop {
p.expect(SyntaxKind::IDENT)?;
p.expect(SyntaxKind::AS_KW)?;
// Handle optional [NOT] MATERIALIZED hint (PostgreSQL 12+)
p.eat(SyntaxKind::NOT_KW)?;
p.eat(SyntaxKind::MATERIALIZED_KW)?;
parenthesis(p)?;

if p.current() == SyntaxKind::COMMA {
Expand Down
Loading