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.

MSSQL query generator uses OFFSET FETCH clause only supported in SQL Server 2012 and up

See original GitHub issue

The query generator uses an OFFSET FETCH clause to apply the offset and limit parameters, which works fine in SQL Server 2012 and newer, but is unsupported in older versions of SQL Server.

Link to relevant code

I found this when I tried to use findById against an SQL Server 2008 R2 database. The server came back with this error message:

Invalid usage of the option NEXT in the FETCH statement.

Looking at the code, it looks like this will also happen when using findOne, or when the offset or limit options are used in a findAll, findAndCount, etc.

So the offset and limit functionality should either be changed to use a syntax supported by all SQL Server versions, or there should be logic to fall back to an old method when a version before 2012 is detected. Or the docs could be updated to specify that only versions newer than 2012 are supported.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Reactions:1
  • Comments:26 (8 by maintainers)

github_iconTop GitHub Comments

7reactions
janmeiercommented, Feb 10, 2017

@accugopher You do realize that nobody got paid a dime to implement sql support? If you were so annoyed by it, why didn’t it do something to fix it?

I know that things are different in the MS world, but do you really expect someone to go to the effort to support a version that was released more than 10 years ago, and reached its end of life last year? Especially when they didn’t need it? Should we have refused to merge the code, because it did not support any verison of sql server released within the last 30 years?

More to the point: I don’t have personal experience with sql server, but judging from https://github.com/sequelize/sequelize/pull/5616/files and https://github.com/sequelize/sequelize/blob/8cbd3750f5f8034cc53096de6ddb43593ba1c983/lib/dialects/mssql/query-generator.js#L769 it seems that we do indeed try to support older versions of sql server. We try to identify the version at startup, but perhaps it’s failing? Perhaps try setting options.databaseVersion manually in the sequelize constructor (It has to be a semver valid string, in this case anything < 11.0.0 should work.

2reactions
accugophercommented, Feb 10, 2017

That is apparently what this means. I just spent the last few weeks on one of the worst projects I’ve ever had in 30+ years of engineering, and largely because this package didn’t support SQL Server 2005. If I had had the time, I would have fixed this myself, but as it stands right now, Sequelize is worthless for use with Microsoft SQL Server the way this has been implemented. To only support SQL Server 2012 or newer is probably the laziest thing I’ve ever seen an engineer do in my years of building and supporting systems, but hey, it fixed their problem, screw you lot, fix it yourself.

Read more comments on GitHub >

github_iconTop Results From Across the Web

SQL Server OFFSET FETCH: Limit The Number of Rows ...
The OFFSET and FETCH clauses are the options of the ORDER BY clause. They allow you to limit the number of rows to...
Read more >
OFFSET FETCH Clause: SQL Server 2012/14 - CodingThis!
While using OFFSET and FETCH clause use of ORDER BY is mandatory. · OFFSET clause is mandatory with FETCH. · TOP cannot be...
Read more >
How to use Offset . . .Fetch Next in SQL SERVER 2008 R2
I get this error : "Incorrect syntax near 'OFFSET'.Invalid usage of the option NEXT in the FETCH statement." when I execute this SQL:...
Read more >
SQL OFFSET FETCH Feature: Loading Large Volumes of ...
In this article, we illustrate how to use the OFFSET FETCH feature as a solution for loading large volumes of data from a...
Read more >
Overview of OFFSET and FETCH Feature of SQL Server 2012
The OFFSET and FETCH clause of SQL Server 2012 provides you an option to fetch only a page or a window of the...
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