Skip to content

fix: create trigger split #227

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 3 commits into from
Mar 10, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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/pglt_statement_splitter/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,23 @@ mod tests {
.expect_statements(vec!["select case when select 2 then 1 else 0 end"]);
}

#[test]
fn create_trigger() {
Tester::from("alter table appointment_status add constraint valid_key check (private.strip_special_chars(key) = key and length(key) > 0 and length(key) < 60);

create trigger default_key before insert on appointment_type for each row when (new.key is null) execute procedure default_key ();

create trigger default_key before insert on appointment_status for each row when (new.key is null) execute procedure default_key ();

alter table deal_type add column key text not null;
")
.expect_statements(vec!["alter table appointment_status add constraint valid_key check (private.strip_special_chars(key) = key and length(key) > 0 and length(key) < 60);",
"create trigger default_key before insert on appointment_type for each row when (new.key is null) execute procedure default_key ();",
"create trigger default_key before insert on appointment_status for each row when (new.key is null) execute procedure default_key ();",
"alter table deal_type add column key text not null;",
]);
}

#[test]
#[timeout(1000)]
fn simple_select() {
Expand Down
10 changes: 9 additions & 1 deletion crates/pglt_statement_splitter/src/parser/ddl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,15 @@ use super::{common::unknown, Parser};
pub(crate) fn create(p: &mut Parser) {
p.expect(SyntaxKind::Create);

unknown(p, &[]);
unknown(
p,
&[
SyntaxKind::Insert,
SyntaxKind::Update,
SyntaxKind::DeleteP,
SyntaxKind::Select,
],
);
}

pub(crate) fn alter(p: &mut Parser) {
Expand Down
Loading