prestodb/presto · error · SQLException

Prepared SQL statement is not a query:

Error message

Prepared SQL statement is not a query: 

What it means

executeQuery on a PrestoPreparedStatement runs 'EXECUTE <statementName>' against the server; if super.execute returns true, the server produced a result set, otherwise the prepared statement was an UPDATE/DDL/other non-query statement. This SQLException signals that the caller used executeQuery on a prepared statement that does not return rows.

Source

Thrown at presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoPreparedStatement.java:110

    @Override
    public void close()
            throws SQLException
    {
        if (isClosed) {
            return;
        }
        super.execute(format("DEALLOCATE PREPARE %s", statementName));
        super.close();
        isClosed = true;
    }

    @Override
    public ResultSet executeQuery()
            throws SQLException
    {
        requireNonBatchStatement();
        if (!super.execute(getExecuteSql(statementName, toValues(parameters)))) {
            throw new SQLException("Prepared SQL statement is not a query: " + originalSql);
        }
        return getResultSet();
    }

    @Override
    public int executeUpdate()
            throws SQLException
    {
        requireNonBatchStatement();
        return Ints.saturatedCast(executeLargeUpdate());
    }

    @Override
    public long executeLargeUpdate()
            throws SQLException
    {
        requireNonBatchStatement();
        if (super.execute(getExecuteSql(statementName, toValues(parameters)))) {

View on GitHub (pinned to 55bb57d202)

Solutions

  1. Use executeUpdate()/executeLargeUpdate() instead when the prepared statement is an INSERT/UPDATE/DELETE or DDL
  2. Inspect the original SQL to confirm whether it should return rows (e.g. a SELECT)
  3. Wrap in try-catch if the statement type is determined dynamically at runtime
Defensive patterns

Strategy: try-catch

When it happens

Trigger: Thrown at presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoPreparedStatement.java:110 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/5483372715897882. Report an issue: GitHub.