prestodb/presto · error · SQLFeatureNotSupportedException

last

Error message

last

What it means

PrestoResultSet throws SQLFeatureNotSupportedException("last") because Presto results stream forward-only and are not buffered in the client; positioning to the last row would require consuming the entire result set, which the driver does not do implicitly.

Source

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

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

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

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

    @Override
    public int getRow()
            throws SQLException
    {
        throw new SQLFeatureNotSupportedException("getRow");
    }

    @Override
    public boolean absolute(int row)
            throws SQLException
    {
        throw new SQLFeatureNotSupportedException("absolute");
    }

    @Override
    public boolean relative(int rows)

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Append ORDER BY ... DESC to the query and read the first row to get what would be the last row
  2. Use a separate SELECT COUNT(*) query to get the row count
  3. Iterate forward to the end, keeping the current row's data in local variables
  4. Cache the full result set in memory if the data set is small

Example fix

// before
rs.last();
int total = rs.getRow();
// after
Statement cnt = conn.createStatement();
ResultSet crs = cnt.executeQuery("SELECT COUNT(*) FROM (" + originalSql + ")");
crs.next();
int total = crs.getInt(1);
Defensive patterns

Strategy: try-catch

Validate before calling

DatabaseMetaData md = conn.getMetaData();
if (!md.supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE)) { /* avoid rs.last() */ }

Try / catch

try { rs.last(); } catch (SQLFeatureNotSupportedException e) { /* iterate forward or use COUNT(*) */ }

Prevention

When it happens

Trigger: Calling ResultSet.last() on a PrestoResultSet, commonly to get the row count via getRow() or to read the final row.

Common situations: Paging logic that shows the last page first, or code using rs.last(); rs.getRow() as a row-count idiom from other JDBC drivers.

Related errors


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