prestodb/presto · error · SQLException

Invalid column index:

Error message

Invalid column index: 

What it means

Private bounds-check helper: any metadata getter that takes a column index first calls column(), which throws this SQLException when the index is less than 1 or greater than the number of columns. JDBC column indexes are 1-based, so index 0 or an index past the last column is invalid.

Source

Thrown at presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoResultSetMetaData.java:258

    {
        if (isWrapperFor(iface)) {
            return (T) this;
        }
        throw new SQLException("No wrapper for " + iface);
    }

    @Override
    public boolean isWrapperFor(Class<?> iface)
            throws SQLException
    {
        return iface.isInstance(this);
    }

    private ColumnInfo column(int column)
            throws SQLException
    {
        if ((column <= 0) || (column > columnInfo.size())) {
            throw new SQLException("Invalid column index: " + column);
        }
        return columnInfo.get(column - 1);
    }
}

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Use 1-based indexes: valid range is 1 to ResultSetMetaData.getColumnCount()
  2. Validate against getColumnCount() before calling metadata getters
  3. Fix loop bounds in metadata-iteration code

Example fix

// before
for (int i = 0; i <= meta.getColumnCount(); i++) { meta.getColumnName(i); }
// after
for (int i = 1; i <= meta.getColumnCount(); i++) { meta.getColumnName(i); }
Defensive patterns

Strategy: validation

Validate before calling

int count = meta.getColumnCount();
if (column < 1 || column > count) {
    throw new IllegalArgumentException("Column index " + column + " out of range 1.." + count);
}

Type guard

boolean validColumn = (column >= 1) && (column <= meta.getColumnCount());

Try / catch

try {
    String name = meta.getColumnName(col);
} catch (SQLException e) {
    if (e.getMessage() != null && e.getMessage().startsWith("Invalid column index")) {
        throw new IllegalArgumentException("Bad column " + col + ", valid range 1.." + meta.getColumnCount(), e);
    } else { throw e; }
}

Prevention

When it happens

Trigger: Calling isCurrency, nullable, isSigned, getColumnDisplaySize, getColumnLabel, or getColumnName with index 0, a negative value, or an index > columnInfo.size() (e.g. iterating 1..count instead of 1..=count mistakes).

Common situations: Loop bounds bugs (for i = 0 instead of 1); assuming 0-based indexes like arrays; reading a column that no longer exists after the query changed; metadata from one ResultSet applied to another.

Related errors


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