question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

SQL Server error with pagination

See original GitHub issue

Using 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:closed
  • Created 5 years ago
  • Comments:7 (4 by maintainers)

github_iconTop GitHub Comments

4reactions
juhguucommented, Sep 18, 2018

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)

0reactions
thetutlagecommented, Sep 27, 2018

Closing, since the issue comes directly from knex and unfortunately there is nothing much we can do.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found