{"record":{"id":"f6c236b8a603bcd9","repo":"prestodb/presto","slug":"query-has-no-columns-s","errorCode":null,"errorMessage":"Query has no columns (#%s)","messagePattern":"Query has no columns \\(#(.+?)\\)","errorType":"exception","errorClass":"SQLException","httpStatus":null,"severity":"error","filePath":"presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoResultSet.java","lineNumber":1749,"sourceCode":"    }\n\n    private static List<Column> getColumns(StatementClient client, Consumer<QueryStats> progressCallback)\n            throws SQLException\n    {\n        while (client.isRunning()) {\n            QueryStatusInfo results = client.currentStatusInfo();\n            progressCallback.accept(QueryStats.create(results.getId(), results.getStats()));\n            List<Column> columns = results.getColumns();\n            if (columns != null) {\n                return columns;\n            }\n            client.advance();\n        }\n\n        verify(client.isFinished());\n        QueryStatusInfo results = client.finalStatusInfo();\n        if (results.getError() == null) {\n            throw new SQLException(format(\"Query has no columns (#%s)\", results.getId()));\n        }\n        throw resultsException(results);\n    }\n\n    private static <T> Iterator<T> flatten(Iterator<Iterable<T>> iterator, long maxRows)\n    {\n        Iterator<T> rowsIterator = concat(transform(iterator, Iterable::iterator));\n        return (maxRows > 0) ? new LengthLimitedIterator<>(rowsIterator, maxRows) : rowsIterator;\n    }\n\n    private static class ResultsPageIterator\n            extends AbstractIterator<Iterable<List<Object>>>\n    {\n        private final StatementClient client;\n        private final Consumer<QueryStats> progressCallback;\n        private final WarningsManager warningsManager;\n        private final boolean isQuery;\n","sourceCodeStart":1731,"sourceCodeEnd":1767,"githubUrl":"https://github.com/prestodb/presto/blob/55bb57d202de3b926896fa966c2c4a44c779634e/presto-jdbc/src/main/java/com/facebook/presto/jdbc/PrestoResultSet.java#L1731-L1767","documentation":"Thrown when the statement finished successfully (no error) but the query result contained zero columns, which the JDBC ResultSet API cannot represent. Presto treats this as a driver-level failure rather than returning an empty metadata ResultSet. The finished query id is included in the message.","triggerScenarios":"Executing a statement that produces no result columns (e.g. INSERT, CREATE TABLE, SET SESSION, CALL, or 'VALUES' mis-parsed) through Statement.executeQuery or via a ResultSet-producing path instead of executeUpdate/execute.","commonSituations":"Using executeQuery for DDL/DML statements that return no columns; running utility statements like PREPARE, RESET SESSION, or EXPLAIN ANALYZE expecting a ResultSet; driver version changes that tightened this validation.","solutions":["Use executeUpdate() or execute() instead of executeQuery() for non-query statements","Ensure the SQL actually returns columns, e.g. SELECT ... rather than INSERT/CREATE","Check the query id in the message in the Presto coordinator logs to confirm what ran","If dynamically building SQL, validate the statement kind before choosing executeQuery"],"exampleFix":"// before\nResultSet rs = stmt.executeQuery(\"CREATE TABLE t AS SELECT 1\");\n// after\nboolean hasResultSet = stmt.execute(\"CREATE TABLE t AS SELECT 1\");\nResultSet rs = hasResultSet ? stmt.getResultSet() : null;","handlingStrategy":"validation","validationCode":"String sql = sqlTrimmed.toLowerCase();\nboolean looksLikeQuery = sql.startsWith(\"select\") || sql.startsWith(\"values\") || sql.startsWith(\"show\") || sql.startsWith(\"describe\") || sql.startsWith(\"explain\");\nif (!looksLikeQuery) throw new IllegalArgumentException(\"executeQuery requires a query; use execute/executeUpdate for: \" + sqlTrimmed);","typeGuard":null,"tryCatchPattern":"try {\n    ResultSet rs = stmt.executeQuery(sql);\n} catch (SQLException e) {\n    if (e.getMessage() != null && e.getMessage().contains(\"Query has no columns\")) {\n        // fall back to non-query execution\n        stmt.execute(sql);\n    } else { throw e; }\n}","preventionTips":["Route DDL/DML to executeUpdate or execute, not executeQuery","Verify SQL kind before choosing the execution API in dynamic SQL code","Log the query id from the message to trace coordinator-side execution"],"tags":["jdbc","statement","empty-result"],"backgroundTag":"statement-is-not-a-query","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"}