Skip to content

Commit c1c4b70

Browse files
committed
Drop dialect flag for LIMIT after the locking clause
The row-locking clause (FOR UPDATE/FOR SHARE/...) just above is parsed for every dialect, so gating only the trailing LIMIT/OFFSET behind a dialect flag was inconsistent. Parse it unconditionally instead and remove supports_limit_after_locking_clause.
1 parent 60a55ba commit c1c4b70

3 files changed

Lines changed: 6 additions & 21 deletions

File tree

src/dialect/mod.rs

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1712,20 +1712,6 @@ pub trait Dialect: Debug + Any {
17121712
false
17131713
}
17141714

1715-
/// Returns true if this dialect supports a `LIMIT`/`OFFSET` clause placed
1716-
/// after the row-locking clause (`FOR UPDATE`/`FOR SHARE`/...), in addition
1717-
/// to the usual position before it.
1718-
///
1719-
/// Example:
1720-
/// ```sql
1721-
/// SELECT * FROM t ORDER BY id FOR UPDATE SKIP LOCKED LIMIT 5;
1722-
/// ```
1723-
///
1724-
/// [PostgreSQL](https://www.postgresql.org/docs/current/sql-select.html)
1725-
fn supports_limit_after_locking_clause(&self) -> bool {
1726-
false
1727-
}
1728-
17291715
/// Returns true if this dialect supports the `INTERPOLATE` clause
17301716
/// in `ORDER BY` expressions.
17311717
///

src/dialect/postgresql.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -291,10 +291,6 @@ impl Dialect for PostgreSqlDialect {
291291
true
292292
}
293293

294-
fn supports_limit_after_locking_clause(&self) -> bool {
295-
true
296-
}
297-
298294
fn supports_set_names(&self) -> bool {
299295
true
300296
}

src/parser/mod.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14480,9 +14480,12 @@ impl<'a> Parser<'a> {
1448014480
}
1448114481
}
1448214482

14483-
// PostgreSQL accepts `LIMIT`/`OFFSET` after the row-locking clause
14484-
// (e.g. `... FOR UPDATE SKIP LOCKED LIMIT 5`) as well as before it.
14485-
if limit_clause.is_none() && self.dialect.supports_limit_after_locking_clause() {
14483+
// Some databases (e.g. PostgreSQL) accept `LIMIT`/`OFFSET` after the
14484+
// row-locking clause (`... FOR UPDATE SKIP LOCKED LIMIT 5`) as well
14485+
// as before it. The locking clause above is parsed for every
14486+
// dialect, so accept a trailing limit here too rather than gating it
14487+
// behind a dialect flag.
14488+
if limit_clause.is_none() {
1448614489
limit_clause = self.parse_optional_limit_clause()?;
1448714490
}
1448814491

0 commit comments

Comments
 (0)