prestodb/presto · error · SQLFeatureNotSupportedException

isBeforeFirst

Error message

isBeforeFirst

What it means

isBeforeFirst requires a scrollable/cursor-positioned ResultSet; Presto result sets are forward-only streams so the driver cannot know the cursor state and throws SQLFeatureNotSupportedException unconditionally. Presto's model never places the cursor in the 'before first' tracked state.

Source

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

        if (value == null) {
            return null;
        }

        return new BigDecimal(String.valueOf(value));
    }

    @Override
    public BigDecimal getBigDecimal(String columnLabel)
            throws SQLException
    {
        return getBigDecimal(columnIndex(columnLabel));
    }

    @Override
    public boolean isBeforeFirst()
            throws SQLException
    {
        throw new SQLFeatureNotSupportedException("isBeforeFirst");
    }

    @Override
    public boolean isAfterLast()
            throws SQLException
    {
        throw new SQLFeatureNotSupportedException("isAfterLast");
    }

    @Override
    public boolean isFirst()
            throws SQLException
    {
        throw new SQLFeatureNotSupportedException("isFirst");
    }

    @Override
    public boolean isLast()

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Use rs.next() and check its boolean return to detect an empty result instead of isBeforeFirst
  2. Collect rows into a list first if you need to know the row count up front
  3. Do not request scrollable result sets — the driver ignores them and the position APIs are unsupported

Example fix

// before
if (!rs.isBeforeFirst()) { /* empty result */ }
// after
if (!rs.next()) { /* empty result */ } else { do { processRow(rs); } while (rs.next()); }
Defensive patterns

Strategy: try-catch

Validate before calling

if (rs instanceof com.facebook.presto.jdbc.PrestoResultSet) {
    // empty-check must use rs.next(), not isBeforeFirst()
}

Type guard

boolean isPrestoResultSet(ResultSet rs) { return rs instanceof com.facebook.presto.jdbc.PrestoResultSet; }

Try / catch

try {
    boolean empty = !rs.isBeforeFirst();
} catch (SQLFeatureNotSupportedException e) {
    boolean empty = !rs.next();
}

Prevention

When it happens

Trigger: Calling rs.isBeforeFirst() on a PrestoResultSet, often to test whether a query returned no rows before iterating.

Common situations: Code written against scrollable result sets (MySQL/PostgreSQL style) ported to Presto; checking for empty results before processing.

Related errors


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