aviralgarg05 opened a new pull request, #38024:
URL: https://github.com/apache/shardingsphere/pull/38024

   ## Description
   
   When inserting into a SINGLE table with `@GeneratedValue(IDENTITY)` on 
PostgreSQL, `getGeneratedKeys()` threw `NumberFormatException` because it 
always read column index 1 from the underlying `ResultSet`. The PostgreSQL JDBC 
driver returns all columns via `RETURNING *` when `RETURN_GENERATED_KEYS` is 
used, so column 1 may not be the generated key column (it could be a string 
column like `event`).
   
   ## Fix
   
   Used the generated key column name from `GeneratedKeyContext` (when 
available) to read the correct column via `resultSet.getObject(columnName)` 
instead of blindly reading `resultSet.getObject(1)`.
   
   Fixes #37485.
   
   ## Changes proposed in this pull request
   
   - Modified `ShardingSpherePreparedStatement.getGeneratedKeys()` to derive 
`columnName` earlier and use it for selection in the fallback path.
   - Modified `ShardingSphereStatement.getGeneratedKeys()` to derive 
`columnName` earlier and use it for selection in the fallback path.
   - Ensured fallback to `resultSet.getObject(1)` remains if `columnName` is 
not available.
   
   ---
   
   Before committing this PR, I'm sure that I have checked the following 
options:
   
   - [x] My code follows the [code of 
conduct](https://shardingsphere.apache.org/community/en/involved/conduct/code/) 
of this project.
   - [x] I have self-reviewed the commit code.
   - [x] I have (or in comment I request) added corresponding labels for the 
pull request. (Labels: `type: bug`, `db: PostgreSQL`, `in: JDBC`)
   - [x] I have passed maven check locally : `./mvnw clean install -B -T1C 
-Dmaven.javadoc.skip -Dmaven.jacoco.skip -e` (Verified with `./mvnw -pl jdbc 
test` - 1148 tests passed).
   - [ ] I have made corresponding changes to the documentation.
   - [x] I have added corresponding unit tests for my changes. (Existing 
`GeneratedKeysResultSetTest` and `ShardingSpherePreparedStatementTest` cover 
these paths and passed).
   - [ ] I have updated the Release Notes of the current development version.
   


-- 
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