{"record":{"id":"72e589f42be40bc1","repo":"prestodb/presto","slug":"value-is-not-a-number","errorCode":null,"errorMessage":"Value is not a number: ","messagePattern":"Value is not a number: ","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoResultSet.java","lineNumber":1730,"sourceCode":"        if (index == null) {\n            throw new SQLException(\"Invalid column label: \" + label);\n        }\n        return index;\n    }\n\n    private static Number toNumber(Object value)\n            throws SQLException\n    {\n        if (value == null) {\n            return 0;\n        }\n        if (value instanceof Number) {\n            return (Number) value;\n        }\n        if (value instanceof Boolean) {\n            return ((Boolean) value) ? 1 : 0;\n        }\n        throw new SQLException(\"Value is not a number: \" + value.getClass().getCanonicalName());\n    }\n\n    private static List<Column> getColumns(StatementClient client, Consumer<QueryStats> progressCallback)\n            throws SQLException\n    {\n        while (client.isRunning()) {\n            QueryStatusInfo results = client.currentStatusInfo();\n            progressCallback.accept(QueryStats.create(results.getId(), results.getStats()));\n            List<Column> columns = results.getColumns();\n            if (columns != null) {\n                return columns;\n            }\n            client.advance();\n        }\n\n        verify(client.isFinished());\n        QueryStatusInfo results = client.finalStatusInfo();\n        if (results.getError() == null) {","sourceCodeStart":1712,"sourceCodeEnd":1748,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoResultSet.java#L1712-L1748","documentation":"Thrown by PrestoResultSet's private number-extraction helper when getObject returned a value that is neither a Number nor a Boolean, so it cannot be converted to a numeric getX (e.g. getLong/getDouble) result. The JDBC driver only coerces numeric and boolean column values; anything else (string, struct, array, map, null object) is rejected. The class name of the offending value is appended to the message.","triggerScenarios":"Calling a numeric getter (getLong, getInt, getDouble, etc.) on a column whose underlying Presto type deserializes to a non-Number Java object, e.g. a VARCHAR, ARRAY, MAP, ROW, or JSON column.","commonSituations":"Schema drift where a column changed from BIGINT to VARCHAR; developers reading a MAP/ARRAY column with getLong assuming a numeric type; using getString-style assumptions on JSON columns; retrieving the wrong column index and hitting a complex-typed column.","solutions":["Check the column's Presto type via ResultSetMetaData.getColumnType/getColumnTypeName before calling numeric getters","Use getObject and convert manually for non-numeric types","Fix the SELECT list so the column is cast to a numeric type in SQL, e.g. CAST(col AS BIGINT)","Verify the column index passed to the getter points at the intended column"],"exampleFix":"// before\nlong v = rs.getLong(3); // column 3 is VARCHAR\n// after\nString s = rs.getString(3);\nlong v = Long.parseLong(s); // or CAST in SQL","handlingStrategy":"type-guard","validationCode":"ResultSetMetaData md = rs.getMetaData();\nString type = md.getColumnTypeName(col);\nboolean numeric = type.matches(\"(TINYINT|SMALLINT|INTEGER|BIGINT|REAL|DOUBLE|DECIMAL).*\");\nif (!numeric) throw new IllegalStateException(\"Column \" + col + \" is \" + type + \", not numeric\");","typeGuard":"Object v = rs.getObject(col);\nif (!(v instanceof Number || v instanceof Boolean)) {\n    throw new IllegalStateException(\"Expected numeric value, got \" + (v == null ? \"null\" : v.getClass().getName()));\n}\nNumber n = (v instanceof Boolean) ? (((Boolean) v) ? 1 : 0) : (Number) v;","tryCatchPattern":"try {\n    long v = rs.getLong(col);\n} catch (SQLException e) {\n    if (e.getMessage() != null && e.getMessage().startsWith(\"Value is not a number\")) {\n        Object raw = rs.getObject(col); // handle non-numeric type explicitly\n    } else { throw e; }\n}","preventionTips":["Check getColumnTypeName before numeric getters","CAST non-numeric columns to numeric types in SQL when arithmetic is needed","Use getString/getObject for VARCHAR, JSON, ARRAY, MAP, ROW columns"],"tags":["jdbc","type-mismatch","resultset"],"backgroundTag":"jdbc-type-mismatch","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}