{"record":{"id":"e9c19aa5d4b11c05","repo":"prestodb/presto","slug":"invalid-offset-row-count","errorCode":"INVALID_OFFSET_ROW_COUNT","errorMessage":"Invalid OFFSET row count: %s","messagePattern":"Invalid OFFSET row count: (.+?)","errorType":"validation","errorClass":"SemanticException","httpStatus":null,"severity":"error","filePath":"presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/StatementAnalyzer.java","lineNumber":5496,"sourceCode":"                    }\n                }\n\n                withScopeBuilder.withNamedQuery(name, withQuery);\n            }\n\n            Scope withScope = withScopeBuilder.build();\n            analysis.setScope(with, withScope);\n            return withScope;\n        }\n\n        private void analyzeOffset(Offset node)\n        {\n            long rowCount;\n            try {\n                rowCount = Long.parseLong(node.getRowCount());\n            }\n            catch (NumberFormatException e) {\n                throw new SemanticException(INVALID_OFFSET_ROW_COUNT, node, \"Invalid OFFSET row count: %s\", node.getRowCount());\n            }\n            if (rowCount < 0) {\n                throw new SemanticException(INVALID_OFFSET_ROW_COUNT, node, \"OFFSET row count must be greater or equal to 0 (actual value: %s)\", rowCount);\n            }\n            analysis.setOffset(node, rowCount);\n        }\n\n        private void verifySelectDistinct(QuerySpecification node, List<Expression> outputExpressions)\n        {\n            for (SortItem item : node.getOrderBy().get().getSortItems()) {\n                Expression expression = item.getSortKey();\n\n                if (expression instanceof LongLiteral) {\n                    continue;\n                }\n\n                Expression rewrittenOrderByExpression = ExpressionTreeRewriter.rewriteWith(new OrderByExpressionRewriter(extractNamedOutputExpressions(node.getSelect())), expression);\n                int index = outputExpressions.indexOf(rewrittenOrderByExpression);","sourceCodeStart":5478,"sourceCodeEnd":5514,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-main-base/src/main/java/com/facebook/presto/sql/analyzer/StatementAnalyzer.java#L5478-L5514","documentation":"Analysis error from analyzeOffset: the OFFSET row count string is not a valid integer literal (Long.parseLong failed). The OFFSET argument must be a plain non-negative integer constant; expressions, decimals, or non-numeric text trigger this guard.","triggerScenarios":"SELECT * FROM t OFFSET 'abc'; or OFFSET with a non-integer literal token in the OFFSET clause.","commonSituations":"Templated SQL where a parameter renders as an empty or malformed string; users quoting the number; copy-paste leaving units like '10 rows' in the literal.","solutions":["Use a plain integer literal: OFFSET 10","Fix the templating so the parameter substitutes a valid integer","Validate user-provided page numbers are numeric before building SQL","Note: a valid negative number is rejected separately (see next error), so also clamp to >= 0"],"exampleFix":"// before\nSELECT * FROM t OFFSET 'ten';\n// after\nSELECT * FROM t OFFSET 10;","handlingStrategy":"validation","validationCode":"if (!offsetStr.matches(\"\\\\d+\")) throw new IllegalArgumentException(\"OFFSET must be a non-negative integer literal: \" + offsetStr);","typeGuard":null,"tryCatchPattern":"try { runQuery(); } catch (SemanticException e) { if (e.getCode() == INVALID_OFFSET_ROW_COUNT.toErrorCode()) { sanitizeOffsetAndRetry(); } throw e; }","preventionTips":["Interpolate offsets only as validated integers","Never quote the OFFSET literal","Strip units/suffixes from user input before templating"],"tags":["offset","sql-syntax","pagination"],"backgroundTag":"invalid-offset-row-count","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"}