{"record":{"id":"e871ce6e02f00a98","repo":"apache/iceberg","slug":"failed-to-execute-query-s","errorCode":null,"errorMessage":"Failed to execute query: %s","messagePattern":"Failed to execute query: (.+?)","errorType":"exception","errorClass":"UncheckedSQLException","httpStatus":null,"severity":"error","filePath":"core/src/main/java/org/apache/iceberg/jdbc/JdbcCatalog.java","lineNumber":813,"sourceCode":"          conn -> {\n            List<R> result = Lists.newArrayList();\n\n            try (PreparedStatement preparedStatement = conn.prepareStatement(sql)) {\n              for (int pos = 0; pos < args.length; pos += 1) {\n                preparedStatement.setString(pos + 1, args[pos]);\n              }\n\n              try (ResultSet rs = preparedStatement.executeQuery()) {\n                while (rs.next()) {\n                  result.add(toRow.apply(rs));\n                }\n              }\n            }\n\n            return result;\n          });\n    } catch (SQLException e) {\n      throw new UncheckedSQLException(e, \"Failed to execute query: %s\", sql);\n    } catch (InterruptedException e) {\n      Thread.currentThread().interrupt();\n      throw new UncheckedInterruptedException(e, \"Interrupted in SQL query\");\n    }\n  }\n\n  private Map<String, String> fetchProperties(Namespace namespace) {\n    if (!namespaceExists(namespace)) {\n      throw new NoSuchNamespaceException(\"Namespace does not exist: %s\", namespace);\n    }\n\n    String namespaceName = JdbcUtil.namespaceToString(namespace);\n\n    List<Map.Entry<String, String>> entries =\n        fetch(\n            row ->\n                new AbstractMap.SimpleImmutableEntry<>(\n                    row.getString(JdbcUtil.NAMESPACE_PROPERTY_KEY),","sourceCodeStart":795,"sourceCodeEnd":831,"githubUrl":"https://github.com/apache/iceberg/blob/86d9c8fc543e7c56c9f624eb725f76c9baff9570/core/src/main/java/org/apache/iceberg/jdbc/JdbcCatalog.java#L795-L831","documentation":"The fetch() helper runs SQL queries (SELECT via RowProducer) and wraps any SQLException into UncheckedSQLException with \"Failed to execute query: %s\". Unlike execute(), fetch does not funnel errors through sqlErrorHandler, so all query failures surface here.","triggerScenarios":"Calling listTables, listNamespaces, listViews, or entries (and any fetch-based read) when the query fails: connection loss, SQL syntax error from a mismatched/legacy catalog schema, missing catalog tables, or permission denied on SELECT.","commonSituations":"Upgrading Iceberg against a JDBC catalog created by an older version (schema drift); DB network outage; user lacking SELECT grants; catalog table accidentally dropped or moved to another schema.","solutions":["Inspect the chained SQLException cause for the database-level reason","Verify connectivity (URL, credentials, network) and that catalog tables exist","Align the catalog schema with the Iceberg version in use (re-initialize or migrate tables)","Grant SELECT privileges on the catalog tables to the configured user"],"exampleFix":"// before\nList<TableIdentifier> tables = catalog.listTables(ns);\n// after\ntry {\n  List<TableIdentifier> tables = catalog.listTables(ns);\n} catch (UncheckedSQLException e) {\n  LOG.error(\"Query failed: {}\", e.getCause().getMessage());\n  throw e;\n}","handlingStrategy":"try-catch","validationCode":"try (Connection c = DriverManager.getConnection(jdbcUrl, user, pass)) {\n  // ensure catalog tables are present before listing\n  DatabaseMetaData md = c.getMetaData();\n  ResultSet rs = md.getTables(null, null, icebergCatalogTableName, null);\n  if (!rs.next()) throw new IllegalStateException(\"Catalog table missing; call initializeCatalogTables\");\n}","typeGuard":null,"tryCatchPattern":"try {\n  List<TableIdentifier> tables = catalog.listTables(ns);\n} catch (UncheckedSQLException e) {\n  LOG.error(\"Catalog query failed: {}\", e.getCause().getMessage(), e.getCause());\n  throw e;\n}","preventionTips":["Initialize catalog tables with the same Iceberg version that reads them","Grant SELECT on catalog tables to the application user","Monitor database availability from connection-pool metrics","Pin Iceberg version to the catalog schema version in use"],"tags":["jdbc","sql","query","database"],"backgroundTag":"sql-query-failed","analyzedSha":"86d9c8fc543e7c56c9f624eb725f76c9baff9570","analyzedAt":"2026-09-12T00:46:39.097Z","contentChangedAt":"2026-09-12T00:46:39.097Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}