{"record":{"id":"16ebb18822e3047d","repo":"prestodb/presto","slug":"last","errorCode":null,"errorMessage":"last","messagePattern":"last","errorType":"exception","errorClass":"SQLFeatureNotSupportedException","httpStatus":null,"severity":"error","filePath":"presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoResultSet.java","lineNumber":664,"sourceCode":"    @Override\n    public void afterLast()\n            throws SQLException\n    {\n        throw new SQLFeatureNotSupportedException(\"afterLast\");\n    }\n\n    @Override\n    public boolean first()\n            throws SQLException\n    {\n        throw new SQLFeatureNotSupportedException(\"first\");\n    }\n\n    @Override\n    public boolean last()\n            throws SQLException\n    {\n        throw new SQLFeatureNotSupportedException(\"last\");\n    }\n\n    @Override\n    public int getRow()\n            throws SQLException\n    {\n        throw new SQLFeatureNotSupportedException(\"getRow\");\n    }\n\n    @Override\n    public boolean absolute(int row)\n            throws SQLException\n    {\n        throw new SQLFeatureNotSupportedException(\"absolute\");\n    }\n\n    @Override\n    public boolean relative(int rows)","sourceCodeStart":646,"sourceCodeEnd":682,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoResultSet.java#L646-L682","documentation":"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.","triggerScenarios":"Calling ResultSet.last() on a PrestoResultSet, commonly to get the row count via getRow() or to read the final row.","commonSituations":"Paging logic that shows the last page first, or code using rs.last(); rs.getRow() as a row-count idiom from other JDBC drivers.","solutions":["Append ORDER BY ... DESC to the query and read the first row to get what would be the last row","Use a separate SELECT COUNT(*) query to get the row count","Iterate forward to the end, keeping the current row's data in local variables","Cache the full result set in memory if the data set is small"],"exampleFix":"// before\nrs.last();\nint total = rs.getRow();\n// after\nStatement cnt = conn.createStatement();\nResultSet crs = cnt.executeQuery(\"SELECT COUNT(*) FROM (\" + originalSql + \")\");\ncrs.next();\nint total = crs.getInt(1);","handlingStrategy":"try-catch","validationCode":"DatabaseMetaData md = conn.getMetaData();\nif (!md.supportsResultSetType(ResultSet.TYPE_SCROLL_INSENSITIVE)) { /* avoid rs.last() */ }","typeGuard":null,"tryCatchPattern":"try { rs.last(); } catch (SQLFeatureNotSupportedException e) { /* iterate forward or use COUNT(*) */ }","preventionTips":["Never use rs.last(); rs.getRow() as a row-count idiom with Presto","Use ORDER BY DESC + LIMIT 1 to read the last row","Compute totals with a separate COUNT(*) query"],"tags":["jdbc","unsupported-operation","forward-only-resultset"],"backgroundTag":"jdbc-resultset-navigation-unsupported","analyzedSha":"55bb57d202de3b926896fa966c2c4a44c779634e","analyzedAt":"2026-09-04T12:50:26.162Z","contentChangedAt":"2026-09-04T12:50:26.162Z","schemaVersion":2},"datasetVersion":"2026-09-11T21:17:09.523Z"}