Skip to content

Commit bfa3217

Browse files
author
Olivier Auverlot
committed
Adding a warning about the use of LIMIT and OFFSET in the blog post
1 parent 70a8c0e commit bfa3217

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

examples/official-site/sqlpage/migrations/71_blog_pagination.sql

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ This component offers many options, and I recommend consulting its documentation
1515
1616
Of course, this component only handles its display and does not implement any logic for data processing or state changes. In this tutorial, we will implement a complete example of using the pagination component with a SQLite database, but the code should work without modification (or with very little modification) with any relational database management system (RDBMS).
1717
18+
> This article serves as a tutorial on the pagination component, rather than an advanced guide on paginated data retrieval from a database. The document employs a straightforward approach using the LIMIT and OFFSET instructions. This approach is interesting only for datasets that are big enough not to be realistically loadable on a single webpage, yet small enough for being queryable with OFFSET...LIMIT.
19+
1820
## Initialization
1921
2022
We first need to define two constants that indicate the maximum number of rows per page and the maximum number of pages that the component should display.
@@ -36,7 +38,7 @@ It is possible that the number of rows in the table is greater than the estimate
3638
```
3739
SET pages_count = (
3840
CASE
39-
WHEN (CAST($pages_count AS INTEGER) * CAST($MAX_RECORD_PER_PAGE AS INTEGER)) = CAST($records_count AS INTEGER) THEN $pages_count
41+
WHEN MOD(CAST($records_count AS INTEGER),CAST($MAX_RECORD_PER_PAGE AS INTEGER)) = 0 THEN $pages_count
4042
ELSE (CAST($pages_count AS INTEGER) + 1)
4143
END
4244
);

0 commit comments

Comments
 (0)