Skip to content

Spanner: Column is not of correct type: expected one of [STRING, NUMERIC] but was NUMERIC, when reading NUMERIC column as Long #2308

@lukaseder

Description

@lukaseder

Environment details

  1. OS type and version: Microsoft Windows [Version 10.0.26100.7171]
  2. Java version: openjdk version "21.0.7" 2025-04-15 LTS
  3. 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

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.

Metadata

Metadata

Assignees

Labels

api: spannerIssues related to the googleapis/java-spanner-jdbc API.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions