Skip to content

Conversation

@bchoudhary6415
Copy link
Collaborator

@bchoudhary6415 bchoudhary6415 commented Sep 1, 2025

This PR addresses issue #164
by adding support for the standard LIMIT and OFFSET syntax in ibm_db_sa when connecting to DB2 version 11.5 and above.

Queries using both LIMIT and OFFSET now generate the simpler, standard SQL syntax:
LIMIT n OFFSET m

Queries using only OFFSET without LIMIT continue to use the older ROW_NUMBER()-based rewrite for compatibility, as DB2 requires a LIMIT or FETCH clause when using OFFSET.

This update improves compatibility and aligns with modern DB2 SQL standards while preserving backward compatibility.

Signed-off-by: Balram Choudhary <bchoudhary@rocketsoftware.com>
@bimalkjha bimalkjha merged commit 56ffd42 into ibmdb:master Sep 1, 2025
2 checks passed
@etern
Copy link

etern commented Nov 23, 2025

I use sqlalchemy with dialect.server_version_info: ('Db2/Linuxx8664', '10.05.0010')

this pr might be the cause of error:

sqlalchemy.exc.ProgrammingError: (ibm_db_dbi.ProgrammingError) ibm_db_dbi::ProgrammingError: Binding Error: [IBM][CLI Driver][DB2/LINUXX8664] SQL0104N An unexpected token "LIMIT" w
as found following "". Expected tokens may include: "FETCH FIRST ROWS ONLY". SQLSTATE=42601 SQLCODE=-104

it occurred after upgrading: 0.4.2 => 0.4.3

@bchoudhary6415 Could you please confirm?

@bchoudhary6415
Copy link
Collaborator Author

Hi @etern,

The LIMIT keyword is supported only starting from Db2 version 11.5 and above. Since your environment is running Db2 10.5, the database does not recognize LIMIT and expects the older syntax using FETCH FIRST n ROWS ONLY.
The recent update in ibm_db_sa (v0.4.3) introduced standard LIMIT/OFFSET syntax for Db2 11.5+, which is why you’re seeing this error after upgrading.

Additionally, Db2 versions lower than 11.5 are out of support. IBM recommends upgrading to a supported version to ensure compatibility and continued support. You can find the official lifecycle and supported versions information here:
IBM Db2 End of Support Dates. [ibm.com]

To resolve this:

  1. Upgrade your Db2 server to version 11.5 or later to use the new syntax and stay within supported versions.
  2. If you need to stay on Db2 10.5, please use the older ibm_db_sa version (v0.4.2 or earlier), which uses the ROW_NUMBER()-based rewrite compatible with your version.

This change was made to align with modern Db2 SQL standards while maintaining backward compatibility through version-specific behavior.

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants