Skip to content

[hotfix] Fix db2 Db2Dialect error#151

Open
andyphone wants to merge 2 commits intoapache:mainfrom
andyphone:fixDB2bug
Open

[hotfix] Fix db2 Db2Dialect error#151
andyphone wants to merge 2 commits intoapache:mainfrom
andyphone:fixDB2bug

Conversation

@andyphone
Copy link

Removed the semicolon from the SQL query as it caused a syntax error . ( Caused by: com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=;;columnA, SOURCE.columnB);END-OF-STATEMENT, DRIVER=4.26.14 ) This error only occurs when a primary key is defined in the table structure.

Removed the semicolon from the SQL query as it caused a syntax error . ( Caused by: com.ibm.db2.jcc.am.SqlSyntaxErrorException: DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601, SQLERRMC=;;columnA, SOURCE.columnB);END-OF-STATEMENT, DRIVER=4.26.14 )
@eskabetxe
Copy link
Member

Thanks for the improvement @andyphone
Could you add some test to validate that we don't introduce this again.
Thanks

@davidradl
Copy link
Contributor

@andyphone are in a position to add tests for this, if not I could take this on.

@andyphone
Copy link
Author

@davidradl I'm not very familiar with the unit testing process on Git, so I'd really appreciate it if you could take care of this. Thanks!

Copy link
Contributor

@RocMarshal RocMarshal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @andyphone for the pr and @eskabetxe @davidradl for the review.

@davidradl May I know the latest new progress about adding unit test cases for the pr?

@github-actions
Copy link

This PR is being marked as stale since it has not had any activity in the last 90 days.
If you would like to keep this PR alive, please leave a comment asking for a review.
If the PR has merge conflicts, update it with the latest from the base branch.

If you are having difficulty finding a reviewer, please reach out to the
community, contact details can be found here: https://flink.apache.org/what-is-flink/community/

If this PR is no longer valid or desired, please feel free to close it.
If no activity occurs in the next 30 days, it will be automatically closed.

@github-actions github-actions bot added the stale label Mar 11, 2026
### Motivation

The SQL generated by `Db2Dialect#getUpsertStatement` previously ended with a trailing semicolon (`;`).

When executing the generated statement through the DB2 JDBC driver, the trailing semicolon may cause a syntax error. In particular, when the target table contains a primary key, the driver may throw the following exception:

```
com.ibm.db2.jcc.am.SqlSyntaxErrorException:
DB2 SQL Error: SQLCODE=-104, SQLSTATE=42601
```

This happens because DB2 JDBC does not expect a semicolon at the end of a SQL statement executed through `PreparedStatement`.

### Changes

This PR removes the trailing semicolon from the SQL statement generated by `Db2Dialect#getUpsertStatement`.

As a result, the generated `MERGE INTO` statement can be executed correctly by the DB2 JDBC driver.

### Tests

The existing `Db2DialectTest#testUpsertStatement` test has been updated to reflect the corrected SQL format (without the trailing semicolon).
This ensures that a trailing semicolon will not be reintroduced in future changes.

### Impact

This change only affects the SQL formatting of the DB2 dialect and does not affect other JDBC dialect implementations.
@andyphone
Copy link
Author

@davidradl plz have a look am i wrong

@andyphone
Copy link
Author

I've added the test update and adjusted the expected SQL accordingly.
Could you please take another look when you have time? @eskabetxe

@RocMarshal RocMarshal changed the title fix db2 Db2Dialect error [hotfix] Fix db2 Db2Dialect error Mar 11, 2026
@RocMarshal
Copy link
Contributor

Hi, @andyphone Thanks for the update.
Pls run mvn spotless:apply in the repo dir to fix the codestyle issue before the next push.

@github-actions github-actions bot removed the stale label Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants