prestodb/presto · warning · SQLException
Max field size must be positive
Error message
Max field size must be positive
What it means
JDBC's setMaxFieldSize limits the maximum bytes returned per field. Presto's driver always returns full values (the limit is ignored), but still validates the argument: a negative max is rejected with this SQLException before the no-op comment.
Source
Thrown at presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoStatement.java:107
connection.set(null);
closeResultSet();
}
@Override
public int getMaxFieldSize()
throws SQLException
{
checkOpen();
return 0;
}
@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 SQLExceptionView on GitHub (pinned to 55bb57d202)
Solutions
- Pass 0 (or a positive value) — in JDBC, 0 means no limit
- Fix sentinel logic that uses -1 for unlimited
- Check the value computed before passing it to setMaxFieldSize
Example fix
// before stmt.setMaxFieldSize(-1); // unlimited? // after stmt.setMaxFieldSize(0); // 0 = no limit
Defensive patterns
Strategy: validation
Validate before calling
if (maxFieldSize < 0) {
throw new IllegalArgumentException("maxFieldSize must be >= 0 (0 = no limit), got " + maxFieldSize);
}
stmt.setMaxFieldSize(maxFieldSize); Try / catch
try {
stmt.setMaxFieldSize(n);
} catch (SQLException e) {
if (e.getMessage() != null && e.getMessage().contains("Max field size must be positive")) {
stmt.setMaxFieldSize(0); // fall back to unlimited
} else { throw e; }
} Prevention
- Use 0, not -1, for 'unlimited' in JDBC setters
- Never pass raw user input or uninitialized ints as field-size limits
- Note Presto ignores this setting anyway — avoid relying on it for truncation
When it happens
Trigger: Calling PrestoStatement.setMaxFieldSize with a negative integer, e.g. -1 used as a sentinel for 'unlimited'.
Common situations: Using -1 as an 'unbounded' sentinel (in this driver 0 is the correct unlimited value); uninitialized/default-negative int variables; porting code from drivers that tolerated negatives.
Related errors
- Max rows must be positive
- Timeout is negative
- Query has no columns (#%s)
- SQL statement is not a query:
- Max rows exceeds limit of 2147483647
AI-assisted analysis of prestodb/presto@55bb57d202 (2026-09-04).
Data as JSON: /api/errors/43bb03daced78068.
Report an issue: GitHub.