Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unexpected token "LIMIT" in DB2

My Rails app is connected to a remote DB2 database, and when migrating I'm stumbling into this error:

==  DropLegacyProject: migrating ========================================
rake aborted!
An error has occurred, this and all later migrations canceled:

RuntimeError: Failed to execute statement due to: [IBM][CLI Driver][DB2/LINUXX8664] SQL0104N  An unexpected token "LIMIT" was found following "".  Expected tokens may include:  "FETCH FIRST <n> ROWS ONLY".  SQLSTATE=42601 SQLCODE=-104: SELECT  projects.* FROM projects WHERE projects.id < 17 LIMIT 1

How can I fix this?

like image 383
Marius Butuc Avatar asked Feb 20 '26 03:02

Marius Butuc


2 Answers

DB2 does not support the LIMIT x keyword.

As the error message says, the proper way to do this would to use FETCH FIRST x ROWS ONLY instead.

like image 127
bhamby Avatar answered Feb 21 '26 15:02

bhamby


As bhamby suggested, DB2 does not support the LIMIT x keyword... by default.

But starting with DB2 v9.7.2, support for LIMIT x can be enabled via the DB2_COMPATIBILITY_VECTOR registry variable:

db2set DB2_COMPATIBILITY_VECTOR=MYS
db2stop
db2start

...and it works!

like image 38
Marius Butuc Avatar answered Feb 21 '26 17:02

Marius Butuc