Skip to main content

apply_paging

Function apply_paging 

Source
pub fn apply_paging(
    sql: &str,
    limit: Option<usize>,
    offset: Option<usize>,
    backend: Backend,
) -> Result<String, SqlError>
Expand description

Apply dialect-specific LIMIT / OFFSET paging to a SQL statement.

Returns the original SQL unchanged if:

  • both limit and offset are None
  • the SQL already contains a LIMIT or OFFSET or FETCH clause
  • the SQL contains multiple statements (;)

ยงDialects

BackendSyntax
Postgres, SQLite, MySQLLIMIT {n} OFFSET {m}
MSSQLOFFSET {m} ROWS FETCH NEXT {n} ROWS ONLY
Oracle (12c+)OFFSET {m} ROWS FETCH NEXT {n} ROWS ONLY

For MSSQL and Oracle, if no ORDER BY is present, a synthetic ORDER BY (SELECT NULL) / ORDER BY 1 is injected and a warning can be emitted by the caller.