Unexpected token “LIMIT” in DB2
-
26-07-2021 - |
質問
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?
解決 2
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!
他のヒント
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.
所属していません StackOverflow