Skip to content

Commit 60a10b5

Browse files
committed
fix: create trigger split
1 parent 5e55838 commit 60a10b5

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

crates/pglt_statement_splitter/src/lib.rs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,23 @@ mod tests {
142142
.expect_statements(vec!["select case when select 2 then 1 else 0 end"]);
143143
}
144144

145+
#[test]
146+
fn create_trigger() {
147+
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);
148+
149+
create trigger default_key before insert on appointment_type for each row when (new.key is null) execute procedure default_key ();
150+
151+
create trigger default_key before insert on appointment_status for each row when (new.key is null) execute procedure default_key ();
152+
153+
alter table deal_type add column key text not null;
154+
")
155+
.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);",
156+
"create trigger default_key before insert on appointment_type for each row when (new.key is null) execute procedure default_key ();",
157+
"create trigger default_key before insert on appointment_status for each row when (new.key is null) execute procedure default_key ();",
158+
"alter table deal_type add column key text not null;",
159+
]);
160+
}
161+
145162
#[test]
146163
#[timeout(1000)]
147164
fn simple_select() {

crates/pglt_statement_splitter/src/parser/ddl.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,15 @@ use super::{common::unknown, Parser};
55
pub(crate) fn create(p: &mut Parser) {
66
p.expect(SyntaxKind::Create);
77

8-
unknown(p, &[]);
8+
unknown(
9+
p,
10+
&[
11+
SyntaxKind::Insert,
12+
SyntaxKind::Update,
13+
SyntaxKind::DeleteP,
14+
SyntaxKind::Select,
15+
],
16+
);
917
}
1018

1119
pub(crate) fn alter(p: &mut Parser) {

0 commit comments

Comments
 (0)