SQL Server error with pagination
See original GitHub issueUsing SQL Server, I have this message when I try to get results after the first page.
“select * from [model] offset @p0 rows fetch next @p1 rows only - Invalid usage of the option next in the FETCH statement.”
MSSQL npm package version
4.1.0
Package version
Lucid: 6.1.2
Node.js and npm version
node: 10.6.0, npm: 6.1.0
Sample Code (to reproduce the issue)
await Model.query().paginate(2)
Issue Analytics
- State:
- Created 5 years ago
- Comments:7 (4 by maintainers)
Top Results From Across the Web
Pagination in SQL Server
Pagination is a process that is used to divide a large data into smaller discrete pages, and this process is also known as...
Read more >SQL Server: pagination by dynamic sql and getting error
3 Answers · SET @SQL='SELECT * FROM (SELECT · CAST(ROW_NUMBER() OVER (ORDER BY LastCSMDeliveredDate DESC) AS INT) AS ''RowNumber'', · ID, · Ticker, ......
Read more >Error with pagination - sql
I get this error when I try to set up pagination for the elements in a feed: ... Find all tables containing column...
Read more >SQL Server error with pagination · Issue #386 · adonisjs/lucid
Apparently this is a KnexJS bug with SQL Server. Paging only works correctly when we include an orderBy clause in the query.
Read more >MS Sql pagination error- incorrect syntax - Bugs
Only seems to impact running a paginated query using MS Sql, I'm using an Azure SQL database. Issue persists with hardcoded values in...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Apparently this is a KnexJS bug with SQL Server. Paging only works correctly when we include an
orderBy
clause in the query.Example:
await Model.query().orderBy('created_at', 'desc').paginate(request.get().page || 1, 20)
Closing, since the issue comes directly from knex and unfortunately there is nothing much we can do.