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
17 changes: 17 additions & 0 deletions crates/pgls_statement_splitter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,23 @@ END;",
.expect_statements(vec!["insert into tbl (id) select 1", "select 3"]);
}

#[test]
fn insert_with_cte() {
let insert = "INSERT INTO target (id)
WITH source AS (
SELECT 1 AS id
)
SELECT id FROM source;";
let input = format!(
"{insert}
SELECT 2;"
);

Tester::from(input.as_str())
.expect_statements(vec![insert, "SELECT 2;"])
.assert_no_errors();
}

#[test]
fn c_style_comments() {
Tester::from("/* this is a test */\nselect 1").expect_statements(vec!["select 1"]);
Expand Down
2 changes: 1 addition & 1 deletion crates/pgls_statement_splitter/src/splitter/dml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ pub(crate) fn insert(p: &mut Splitter) -> SplitterResult {
p.expect(SyntaxKind::INSERT_KW)?;
p.expect(SyntaxKind::INTO_KW)?;

unknown(p, &[SyntaxKind::SELECT_KW])
unknown(p, &[SyntaxKind::WITH_KW, SyntaxKind::SELECT_KW])
}

pub(crate) fn update(p: &mut Splitter) -> SplitterResult {
Expand Down