shijie-328931589 opened a new issue, #34424:
URL: https://github.com/apache/shardingsphere/issues/34424

   ## Bug Report
   
   ### Which version of ShardingSphere did you use?
   5.5.1
   ### Which project did you use? ShardingSphere-JDBC or ShardingSphere-Proxy?
   ShardingSphere-JDBC 
   ### Expected behavior
   use postgresql, the sql is " insert into transactional_table(id,user_name) 
values (?,?) on conflict(id) do update set user_name = ? ", hope this sql 
executed success
   I code
   ### Actual behavior
   executed error, the error message: [ 32280
   
](https://github.com/apache/shardingsphere/issues/32280#issuecomment-2603504422)###
 Reason analyze (If you can)
   
   the reason: 
   In InsertStatementBinder, the  method "copy", 
sqlStatement.getOnDuplicateKeyColumns().ifPresent(result::setOnDuplicateKeyColumns);
   but  PostgreSQLInsertStatement missing setOnDuplicateKeyColumns
   ```
       @SneakyThrows(ReflectiveOperationException.class)
       private InsertStatement copy(final InsertStatement sqlStatement) {
           InsertStatement result = 
sqlStatement.getClass().getDeclaredConstructor().newInstance();
           result.getValues().addAll(sqlStatement.getValues());
           sqlStatement.getSetAssignment().ifPresent(result::setSetAssignment);
           
sqlStatement.getOnDuplicateKeyColumns().ifPresent(result::setOnDuplicateKeyColumns);
           sqlStatement.getOutputSegment().ifPresent(result::setOutputSegment);
           
sqlStatement.getMultiTableInsertType().ifPresent(result::setMultiTableInsertType);
           
sqlStatement.getMultiTableInsertIntoSegment().ifPresent(result::setMultiTableInsertIntoSegment);
           
sqlStatement.getMultiTableConditionalIntoSegment().ifPresent(result::setMultiTableConditionalIntoSegment);
           
sqlStatement.getReturningSegment().ifPresent(result::setReturningSegment);
           
result.addParameterMarkerSegments(sqlStatement.getParameterMarkerSegments());
           
result.getCommentSegments().addAll(sqlStatement.getCommentSegments());
           result.getVariableNames().addAll(sqlStatement.getVariableNames());
           return result;
       }
   ```
   
   ### Steps to reproduce the behavior, such as: SQL to execute, sharding rule 
configuration, when exception occur etc.
   
   ### Example codes for reproduce this issue (such as a github link).
   ```
   public void executeSql1(String index) throws Exception {
       ShardingInfo currentShardingInfo = 
RoutingDataSourceUtils.getCurrentShardingInfo();
       ShardingSphereDataSource wrappedDataSource = 
(ShardingSphereDataSource)currentShardingInfo.getWrappedDataSource();
       try(Connection connection = wrappedDataSource.getConnection()){
           String sql = "insert into transactional_table(id,user_name) values 
(?,?) on conflict(id) do update set user_name = ?";
           PreparedStatement preparedStatement = 
connection.prepareStatement(sql);
           preparedStatement.setLong(1, 100L);
           preparedStatement.setString(2, "test");
           preparedStatement.setString(2, "test");
           preparedStatement.execute();
       }
   }
   ```


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