Skip to content

Conversation

takluyver
Copy link
Contributor

@takluyver takluyver commented Oct 18, 2025

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 an Option<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 🙂

@takluyver takluyver force-pushed the sqlite-trigger-no-period branch from 6e366a8 to f3ac084 Compare October 18, 2025 16:45
Comment on lines 5595 to 5608
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()?)
};
Copy link
Contributor

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

Copy link
Contributor Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants