prestodb/presto · error · SQLException

Value is not a number:

Error message

Value is not a number: 

What it means

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.

Solutions

  1. Check the column's Presto type via ResultSetMetaData.getColumnType/getColumnTypeName before calling numeric getters
  2. Use getObject and convert manually for non-numeric types
  3. Fix the SELECT list so the column is cast to a numeric type in SQL, e.g. CAST(col AS BIGINT)
  4. Verify the column index passed to the getter points at the intended column

Example fix

// before
long v = rs.getLong(3); // column 3 is VARCHAR
// after
String s = rs.getString(3);
long v = Long.parseLong(s); // or CAST in SQL
Defensive patterns

Strategy: type-guard

Validate before calling

ResultSetMetaData md = rs.getMetaData();
String type = md.getColumnTypeName(col);
boolean numeric = type.matches("(TINYINT|SMALLINT|INTEGER|BIGINT|REAL|DOUBLE|DECIMAL).*");
if (!numeric) throw new IllegalStateException("Column " + col + " is " + type + ", not numeric");

Type guard

Object v = rs.getObject(col);
if (!(v instanceof Number || v instanceof Boolean)) {
    throw new IllegalStateException("Expected numeric value, got " + (v == null ? "null" : v.getClass().getName()));
}
Number n = (v instanceof Boolean) ? (((Boolean) v) ? 1 : 0) : (Number) v;

Try / catch

try {
    long v = rs.getLong(col);
} catch (SQLException e) {
    if (e.getMessage() != null && e.getMessage().startsWith("Value is not a number")) {
        Object raw = rs.getObject(col); // handle non-numeric type explicitly
    } else { throw e; }
}

Prevention

When it happens

Trigger: 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.

Common situations: 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.

Related errors


AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04). Data as JSON: /api/errors/72e589f42be40bc1. Report an issue: GitHub.

Appendix: source

Thrown at presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoResultSet.java:1730

        if (index == null) {
            throw new SQLException("Invalid column label: " + label);
        }
        return index;
    }

    private static Number toNumber(Object value)
            throws SQLException
    {
        if (value == null) {
            return 0;
        }
        if (value instanceof Number) {
            return (Number) value;
        }
        if (value instanceof Boolean) {
            return ((Boolean) value) ? 1 : 0;
        }
        throw new SQLException("Value is not a number: " + value.getClass().getCanonicalName());
    }

    private static List<Column> getColumns(StatementClient client, Consumer<QueryStats> progressCallback)
            throws SQLException
    {
        while (client.isRunning()) {
            QueryStatusInfo results = client.currentStatusInfo();
            progressCallback.accept(QueryStats.create(results.getId(), results.getStats()));
            List<Column> columns = results.getColumns();
            if (columns != null) {
                return columns;
            }
            client.advance();
        }

        verify(client.isFinished());
        QueryStatusInfo results = client.finalStatusInfo();
        if (results.getError() == null) {

View on GitHub (pinned to 55bb57d202)