prestodb/presto · warning · SQLException
Max rows exceeds limit of 2147483647
Error message
Max rows exceeds limit of 2147483647
What it means
getMaxRows() (the legacy int API) delegates to getLargeMaxRows() (a long) and throws this SQLException if the configured max-rows limit exceeds Integer.MAX_VALUE (2147483647), since it cannot be represented as an int. The large-rows JDBC 4.2 API has no such limit.
Source
Thrown at presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoStatement.java:118
@Override
public void setMaxFieldSize(int max)
throws SQLException
{
checkOpen();
if (max < 0) {
throw new SQLException("Max field size must be positive");
}
// ignore: full values are always returned
}
@Override
public int getMaxRows()
throws SQLException
{
long result = getLargeMaxRows();
if (result > Integer.MAX_VALUE) {
throw new SQLException("Max rows exceeds limit of 2147483647");
}
return toIntExact(result);
}
@Override
public long getLargeMaxRows()
throws SQLException
{
checkOpen();
return maxRows.get();
}
@Override
public void setMaxRows(int max)
throws SQLException
{
setLargeMaxRows(max);
}View on GitHub (pinned to 55bb57d202)
Solutions
- Use getLargeMaxRows()/setLargeMaxRows() for limits above 2147483647
- Keep max rows <= Integer.MAX_VALUE if the int API must be used
- Avoid Long.MAX_VALUE as an 'unlimited' sentinel; use 0 if the driver supports it, or track 'unlimited' in your own code
Example fix
// before stmt.setLargeMaxRows(Long.MAX_VALUE); int m = stmt.getMaxRows(); // throws // after stmt.setLargeMaxRows(Long.MAX_VALUE); long m = stmt.getLargeMaxRows();
Defensive patterns
Strategy: validation
Validate before calling
long limit = stmt.getLargeMaxRows();
if (limit > Integer.MAX_VALUE) {
// do not call the int API
}
int maxRows = (limit > Integer.MAX_VALUE) ? Integer.MAX_VALUE : (int) limit; Type guard
boolean fitsInt = (limit >= 0) && (limit <= (long) Integer.MAX_VALUE);
Try / catch
try {
int m = stmt.getMaxRows();
} catch (SQLException e) {
if (e.getMessage() != null && e.getMessage().contains("Max rows exceeds limit")) {
long m = stmt.getLargeMaxRows(); // use the long API
} else { throw e; }
} Prevention
- Use the Large (JDBC 4.2) variants getLargeMaxRows/setLargeMaxRows consistently
- Never set limits above Integer.MAX_VALUE if legacy int APIs are in use
- Avoid Long.MAX_VALUE as an unbounded sentinel when mixing int/long APIs
When it happens
Trigger: Calling getMaxRows() after setLargeMaxRows was given a value > Integer.MAX_VALUE (e.g. Long.MAX_VALUE used to mean 'no limit'), or any code path that sets an oversized long limit then reads via the int API.
Common situations: Mixing JDBC 4.1 setMaxRows with JDBC 4.2 setLargeMaxRows; using Long.MAX_VALUE as an unbounded sentinel then calling the int getter; legacy framework code reading getMaxRows().
Related errors
- Query has no columns (#%s)
- SQL statement is not a query:
- Max field size must be positive
- Max rows must be positive
- NOT_SUPPORTED
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/b5dae4a0f1d3d07d.
Report an issue: GitHub.