siwen-yu opened a new pull request, #11730:
URL: https://github.com/apache/seatunnel/pull/11730

   ### Purpose of this pull request
   
   Fix the MERGE (upsert) SQL generation in JDBC dialects for tables whose 
every column is a primary/unique key (i.e. no non-key field to update). 
Previously `getUpsertStatement` always appended `WHEN MATCHED THEN UPDATE SET 
<clause>`; when `updateSetClause` is empty this yielded invalid SQL (`UPDATE 
SET` with an empty body) and the database threw a syntax error. Affected 
dialects: DM, Oracle, SAP HANA, SQL Server, Vertica, Xugu.
   
   This PR introduces a `matchedClause` string that is omitted entirely when 
there is nothing to update, keeping the behaviour identical when 
`updateSetClause` is non-empty.
   
   Closes #11729
   
   ### Does this PR introduce any user-facing change?
   
   Yes (bug fix, no API/config/schema change).
   - Before: upserting into an all-key table via the above dialects failed with 
a SQL syntax error (empty `UPDATE SET` body).
   - After: the MERGE statement is generated correctly; matched rows are left 
unchanged and unmatched rows inserted, so the job succeeds.
   
   ### How was this patch tested?
   
   Manually verified by configuring a JDBC sink (DM / Oracle / etc.) against an 
all-key table and running an upsert job:
   1. Created a table whose all columns are primary keys, e.g. `CREATE TABLE 
all_key_t (a INT PRIMARY KEY, b INT PRIMARY KEY);`
   2. Ran a SeaTunnel job that upserts multiple rows into the table.
   3. Confirmed the generated MERGE statement no longer contains an empty 
`UPDATE SET` and the job completes successfully.
   
   ### Check list
   
   - [X] No new Jar binary package added
   - [ ] Documentation update — not needed (internal SQL generation fix, no 
user-facing config)
   - [ ] incompatible-changes.md — not needed (backward compatible)
   - [ ] Connector checklist (plugin-mapping/pom/labeler/e2e) — not applicable, 
no new connector added
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to