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
1 change: 1 addition & 0 deletions fuzz/fuzz_seeds/mysql_2615_delete_limit.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DELETE FROM customers LIMIT 100
11 changes: 11 additions & 0 deletions src/dialect/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -713,6 +713,17 @@ pub trait Dialect: Debug + Any {
false
}

/// Returns true if the dialect supports `LIMIT` in `DELETE` statements.
///
/// ```sql
/// DELETE FROM foo LIMIT 10;
/// ```
/// See <https://dev.mysql.com/doc/refman/8.4/en/delete.html>
/// and <https://www.sqlite.org/lang_delete.html>
fn supports_delete_limit(&self) -> bool {
false
}

/// Returns true if the dialect supports an `EXCEPT` clause following a
/// wildcard in a select list.
///
Expand Down
5 changes: 5 additions & 0 deletions src/dialect/mysql.rs
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,11 @@ impl Dialect for MySqlDialect {
true
}

/// See: <https://dev.mysql.com/doc/refman/8.4/en/delete.html>
fn supports_delete_limit(&self) -> bool {
true
}

fn supports_data_type_signed_suffix(&self) -> bool {
true
}
Expand Down
5 changes: 5 additions & 0 deletions src/dialect/sqlite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,11 @@ impl Dialect for SQLiteDialect {
true
}

/// See: <https://www.sqlite.org/lang_delete.html>
fn supports_delete_limit(&self) -> bool {
true
}

fn supports_asc_desc_in_column_definition(&self) -> bool {
true
}
Expand Down
2 changes: 1 addition & 1 deletion src/parser/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15233,7 +15233,7 @@ impl<'a> Parser<'a> {
} else {
vec![]
};
let limit = if self.parse_keyword(Keyword::LIMIT) {
let limit = if self.dialect.supports_delete_limit() && self.parse_keyword(Keyword::LIMIT) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

DELETE ... ORDER BY, parsed a few lines above, is also MySQL/SQLite-only but stays ungated, so DELETE FROM t ORDER BY a still parses in every dialect. Same for UPDATE ... LIMIT. If we gate on dialect, it would be more consistent to gate these together.

self.parse_limit()?
} else {
None
Expand Down
13 changes: 13 additions & 0 deletions tests/sqlparser_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23106,3 +23106,16 @@ fn parse_alter_table_reset_options() {
);
}
}

#[test]
fn parse_delete_limit_dialect_gated() {
let sql = "DELETE FROM customers LIMIT 100";
all_dialects_where(|d| d.supports_delete_limit()).verified_stmt(sql);

assert_eq!(
all_dialects_where(|d| !d.supports_delete_limit()).parse_sql_statements(sql),
Err(ParserError::ParserError(
"Expected: end of statement, found: LIMIT".to_string()
))
);
}
Loading