prestodb/presto · error · SQLFeatureNotSupportedException

beforeFirst

Error message

beforeFirst

What it means

beforeFirst requires a scrollable cursor to rewind to the start of the result set; Presto results are forward-only server-side streams that cannot be repositioned, so the driver throws SQLFeatureNotSupportedException unconditionally. Re-reading a result set is impossible without re-executing the query.

Source

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

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

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

    @Override
    public void beforeFirst()
            throws SQLException
    {
        throw new SQLFeatureNotSupportedException("beforeFirst");
    }

    @Override
    public void afterLast()
            throws SQLException
    {
        throw new SQLFeatureNotSupportedException("afterLast");
    }

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

    @Override
    public boolean last()

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Re-execute the statement (or run a new query) to iterate again
  2. Consume the ResultSet once and buffer rows (List<T>) if multiple passes are needed
  3. Restructure consumers to accept a single forward-only pass

Example fix

// before
consume(rs);
rs.beforeFirst();
consumeAgain(rs);
// after
List<Row> rows = readAll(rs);
consume(rows);
consumeAgain(rows);
Defensive patterns

Strategy: try-catch

Validate before calling

if (rs instanceof com.facebook.presto.jdbc.PrestoResultSet) {
    throw new UnsupportedOperationException("beforeFirst is not supported; buffer rows or re-execute the query");
}

Type guard

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

Try / catch

try {
    rs.beforeFirst();
} catch (SQLFeatureNotSupportedException e) {
    // re-run the statement or iterate a buffered List<Row>
}

Prevention

When it happens

Trigger: Calling rs.beforeFirst() to restart iteration over a PrestoResultSet, usually after consuming some rows.

Common situations: Code that iterates a ResultSet twice (e.g. once for headers, once for data); caching frameworks assuming scrollable results.

Related errors


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