-
Notifications
You must be signed in to change notification settings - Fork 670
SQLite: make period optional for CREATE TRIGGER #2071
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
base: main
Are you sure you want to change the base?
Conversation
6e366a8
to
f3ac084
Compare
src/parser/mod.rs
Outdated
let period = if dialect_of!(self is SQLiteDialect) | ||
&& self | ||
.peek_one_of_keywords(&[ | ||
Keyword::INSERT, | ||
Keyword::UPDATE, | ||
Keyword::DELETE, | ||
Keyword::TRUNCATE, | ||
]) | ||
.is_some() | ||
{ | ||
None // SQLite: period can be skipped (equivalent to BEFORE) | ||
} else { | ||
Some(self.parse_trigger_period()?) | ||
}; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we can do something like this to support optionality
let period = self.maybe_parse(|parser| parser.parse_trigger_period());
It would imply the same behavior for other dialects than sqlite but that's okay for the parser to be more permissive
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks!
Allowing this for all dialects changes an error message that is tested for the Postgres dialect. For now I'll change that test so that everything passes, but if you'd prefer a different direction, like making it conditional on the dialect again, I can easily cut that commit off.
Co-authored-by: Ifeanyi Ubah <[email protected]>
Co-authored-by: Ifeanyi Ubah <[email protected]>
I just tried out the new CREATE TRIGGER support for SQLite, but ran across a limitation. SQLite's CREATE TRIGGER statement makes the period (
BEFORE
,AFTER
,INSTEAD OF
) optional. Leaving it out is equivalent to BEFORE. This allows that in sqlparser, making the field anOption<TriggerPeriod>
.This may well be clumsily implemented - I don't write all that much Rust, so suggestions are welcome. I've enabled this only for SQLite for now - I haven't researched if the same syntax is legal in any other dialects.
cc @LucaCappelletti94 - and thanks for adding the overall CREATE TRIGGER support 🙂