-
Notifications
You must be signed in to change notification settings - Fork 136
Closed
Labels
api: spannerIssues related to the googleapis/java-spanner API.Issues related to the googleapis/java-spanner API.
Description
Environment details
Looks like when the query has returning clause, one of the precondition check fails as it expects only SELECTs. But as per docs we should have the ability to use INSERT INTO ... VALUES (...) ... THEN RETURN .... It works as expected when using the Spanner studio UI.
Note - We are using retryAbortsInternally=false
- com.google.cloud.spanner.connection.AbstractMultiUseTransaction#executeQueryAsync
- OS type and version: macOS 15.6.1 (24G90)
- Java version: openjdk version "25" 2025-09-16 LTS
- google-cloud-spanner-jdbc 2.33.1
- google-cloud-spanner 6.102.0
Steps to reproduce
- Dialect = Google SQL
retryAbortsInternally=false- Create a test table with following DDL
CREATE SEQUENCE IF NOT EXISTS test_seq OPTIONS (
sequence_kind = 'bit_reversed_positive',
skip_range_min = 1,
skip_range_max = 1000,
start_with_counter = 1
);
CREATE TABLE IF NOT EXISTS test
(
id INT64 NOT NULL DEFAULT (GET_NEXT_SEQUENCE_VALUE(SEQUENCE test_seq)),
value INT64 NOT NULL
) PRIMARY KEY (id);Code example
private final DataSource spannerDatasource;
public long test() throws SQLException {
try (Connection connection = spannerDatasource.getConnection();
PreparedStatement insertStmt = connection.prepareStatement(
"INSERT INTO test(value) VALUES (?) THEN RETURN id",
Statement.RETURN_GENERATED_KEYS)) {
insertStmt.setLong(1, 123L);
try (ResultSet rs = insertStmt.executeQuery()) {
if (rs.next()) {
return rs.getLong("id");
}
}
}
}Stack trace
java.lang.IllegalArgumentException: Statement is not a query
at com.google.common.base.Preconditions.checkArgument(Preconditions.java:143)
at com.google.cloud.spanner.connection.AbstractMultiUseTransaction.executeQueryAsync(AbstractMultiUseTransaction.java:132)
at com.google.cloud.spanner.connection.ReadWriteTransaction.executeQueryAsync(ReadWriteTransaction.java:692)
at com.google.cloud.spanner.connection.ConnectionImpl.internalExecuteQuery(ConnectionImpl.java:2088)
at com.google.cloud.spanner.connection.ConnectionImpl.parseAndExecuteQuery(ConnectionImpl.java:1768)
at com.google.cloud.spanner.connection.ConnectionImpl.executeQuery(ConnectionImpl.java:1576)
at com.google.cloud.spanner.jdbc.AbstractJdbcStatement.lambda$executeQuery$0(AbstractJdbcStatement.java:238)
at com.google.cloud.spanner.jdbc.AbstractJdbcStatement.doWithStatementTimeout(AbstractJdbcStatement.java:260)
at com.google.cloud.spanner.jdbc.AbstractJdbcStatement.doWithStatementTimeout(AbstractJdbcStatement.java:247)
at com.google.cloud.spanner.jdbc.AbstractJdbcStatement.executeQuery(AbstractJdbcStatement.java:234)
at com.google.cloud.spanner.jdbc.AbstractJdbcStatement.executeQuery(AbstractJdbcStatement.java:225)
at com.google.cloud.spanner.jdbc.JdbcPreparedStatement.executeQuery(JdbcPreparedStatement.java:85)
External references such as API reference guides
Metadata
Metadata
Assignees
Labels
api: spannerIssues related to the googleapis/java-spanner API.Issues related to the googleapis/java-spanner API.