prestodb/presto · error · SQLException

Invalid fetch direction

Error message

Invalid fetch direction

What it means

setFetchDirection in PrestoStatement validates the direction argument via validFetchDirection(direction); only FETCH_FORWARD (and unknown/ignored values it accepts) are permitted since Presto fetches rows forward-only, so an invalid direction constant throws this SQLException.

Source

Thrown at presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoStatement.java:371

    {
        checkOpen();
        return currentUpdateCount.get();
    }

    @Override
    public boolean getMoreResults()
            throws SQLException
    {
        return getMoreResults(CLOSE_CURRENT_RESULT);
    }

    @Override
    public void setFetchDirection(int direction)
            throws SQLException
    {
        checkOpen();
        if (!validFetchDirection(direction)) {
            throw new SQLException("Invalid fetch direction");
        }
        // ignore: fetch direction is always forward
    }

    @Override
    public int getFetchDirection()
            throws SQLException
    {
        checkOpen();
        return ResultSet.FETCH_FORWARD;
    }

    @Override
    public void setFetchSize(int rows)
            throws SQLException
    {
        checkOpen();
        if (rows < 0) {

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Use ResultSet.FETCH_FORWARD (the only supported direction)
  2. Remove setFetchDirection calls that request scrollable/ reverse cursors
  3. Catch SQLException in generic JDBC code that may set arbitrary directions
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoStatement.java:371 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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