Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No value specified for parameter exception when use postgresql on duplicate #34424

Open
shijie-328931589 opened this issue Jan 22, 2025 · 3 comments · May be fixed by #34425
Open

No value specified for parameter exception when use postgresql on duplicate #34424

shijie-328931589 opened this issue Jan 22, 2025 · 3 comments · May be fixed by #34425

Comments

@shijie-328931589
Copy link

shijie-328931589 commented Jan 22, 2025

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
### 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(3, "test");
        preparedStatement.execute();
    }
}
@omkar-shitole
Copy link
Contributor

Hi @shijie-328931589

Could you kindly double-check to ensure that the parameter indexes in the PreparedStatement are set incrementally? If the issue still persists, it would be great if you could share the updated error stack so, I'll attempt to reproduce the same error and further debugging.
preparedStatement.setString(2, "test"); preparedStatement.setString(2, "test");

@shijie-328931589
Copy link
Author

shijie-328931589 commented Jan 22, 2025

org.postgresql.util.PSQLException: 未设定参数值 3 的内容。

	at org.postgresql.core.v3.SimpleParameterList.checkAllParametersSet(SimpleParameterList.java:275)
	at org.postgresql.core.v3.QueryExecutorImpl.execute(QueryExecutorImpl.java:307)
	at org.postgresql.jdbc.PgStatement.executeInternal(PgStatement.java:473)
	at org.postgresql.jdbc.PgStatement.execute(PgStatement.java:393)
	at org.postgresql.jdbc.PgPreparedStatement.executeWithFlags(PgPreparedStatement.java:164)
	at org.postgresql.jdbc.PgPreparedStatement.execute(PgPreparedStatement.java:153)
	at java.base/jdk.internal.reflect.DirectMethodHandleAccessor.invoke(DirectMethodHandleAccessor.java:103)
	at java.base/java.lang.reflect.Method.invoke(Method.java:580)
	at org.apache.tomcat.jdbc.pool.StatementFacade$StatementProxy.invoke(StatementFacade.java:114)
	at jdk.proxy2/jdk.proxy2.$Proxy33.execute(Unknown Source)
	at org.apache.shardingsphere.driver.executor.callback.execute.ExecuteCallbackFactory$1.executeSQL(ExecuteCallbackFactory.java:55)
	at org.apache.shardingsphere.driver.executor.callback.execute.ExecuteCallbackFactory$1.executeSQL(ExecuteCallbackFactory.java:51)
	at org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutorCallback.execute(JDBCExecutorCallback.java:85)
	at org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutorCallback.execute(JDBCExecutorCallback.java:64)
	at org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine.syncExecute(ExecutorEngine.java:99)
	at org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine.parallelExecute(ExecutorEngine.java:95)
	at org.apache.shardingsphere.infra.executor.kernel.ExecutorEngine.execute(ExecutorEngine.java:78)
	at org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutor.execute(JDBCExecutor.java:66)
	at org.apache.shardingsphere.infra.executor.sql.execute.engine.driver.jdbc.JDBCExecutor.execute(JDBCExecutor.java:50)
	at org.apache.shardingsphere.driver.executor.engine.pushdown.jdbc.DriverJDBCPushDownExecuteExecutor.doExecute(DriverJDBCPushDownExecuteExecutor.java:102)
	at org.apache.shardingsphere.driver.executor.engine.pushdown.jdbc.DriverJDBCPushDownExecuteExecutor.lambda$execute$0(DriverJDBCPushDownExecuteExecutor.java:87)
	at org.apache.shardingsphere.driver.executor.engine.transaction.DriverTransactionalExecutor.execute(DriverTransactionalExecutor.java:56)
	at org.apache.shardingsphere.driver.executor.engine.pushdown.jdbc.DriverJDBCPushDownExecuteExecutor.execute(DriverJDBCPushDownExecuteExecutor.java:86)
	at org.apache.shardingsphere.driver.executor.engine.DriverExecuteExecutor.executePushDown(DriverExecuteExecutor.java:117)
	at org.apache.shardingsphere.driver.executor.engine.DriverExecuteExecutor.execute(DriverExecuteExecutor.java:105)
	at org.apache.shardingsphere.driver.executor.engine.facade.standard.StandardDriverExecutorFacade.execute(StandardDriverExecutorFacade.java:110)
	at org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.execute(ShardingSpherePreparedStatement.java:248)

The bug still exists, in the pr34425, it`s work ok

@terrymanu
Copy link
Member

terrymanu commented Jan 24, 2025

But the pull request has not finished yet.

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 a pull request may close this issue.

3 participants