googleapis / googleapis/google-cloud-java

[java-spanner-jdbc] Spanner: Column is not of correct type: expected one of [STRING, NUMERIC] but was NUMERIC, when reading NUMERIC column as Long

Open
#12,274 0 comments 0 reactions 1 assignee Claimed by @olavloite View on GitHub
api: spanner
Dominant language
Java
Stars
2.1k
Forks
1.2k
Avg merge
1d 23h
Merged PRs (30d)
154

Description

#### Environment details

2. OS type and version: Microsoft Windows [Version 10.0.26100.7171]
3. Java version: openjdk version "21.0.7" 2025-04-15 LTS
4. version(s): I'm working with the spanner emulator: https://github.com/GoogleCloudPlatform/cloud-spanner-emulator and JDBC driver version: `com.google.cloud:google-cloud-spanner-jdbc:2.34.0`

#### Steps to reproduce

Read a `NUMERIC` value using `ResultSet::getLong`

#### Code example

```java
try (
Statement s = connection.createStatement();
ResultSet rs = s.executeQuery("select cast(1 as numeric)")
) {
while (rs.next()) {
System.out.println(rs.getLong(1));
}
}
```

#### Stack trace

```
Exception in thread "main" java.lang.IllegalStateException: Column 0 is not of correct type: expected one of [STRING, NUMERIC] but was NUMERIC
at com.google.common.base.Preconditions.checkState(Preconditions.java:853)
at com.google.cloud.spanner.AbstractStructReader.checkNonNullOfTypes(AbstractStructReader.java:724)
at com.google.cloud.spanner.AbstractStructReader.getString(AbstractStructReader.java:238)
at com.google.cloud.spanner.connection.DirectExecuteResultSet.getString(DirectExecuteResultSet.java:224)
at com.google.cloud.spanner.jdbc.JdbcResultSet.getLong(JdbcResultSet.java:435)
at org.jooq.testscripts.JDBC.main(JDBC.java:45)
```

This doesn't happen when reading it using `ResultSet::getInt`, for example.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.