{"record":{"id":"4ebcaa4e68241d11","repo":"apache/beam","slug":"failed-to-query-v","errorCode":null,"errorMessage":"failed to query: %v","messagePattern":"failed to query: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/io/databaseio/database.go","lineNumber":175,"sourceCode":"\t//TODO move DB Open and Close to Setup and Teardown methods or StartBundle and FinishBundle\n\tdb, err := sql.Open(f.Driver, f.Dsn)\n\tif err != nil {\n\t\treturn errors.Wrapf(err, \"failed to open database: %v\", f.Driver)\n\t}\n\tdefer db.Close()\n\tprojection := \"*\"\n\tif len(f.Columns) > 0 {\n\t\tprojection = strings.Join(f.Columns, \",\")\n\t}\n\tdql := fmt.Sprintf(\"SELECT %v FROM  %v WHERE 1 = 0\", projection, f.Table)\n\tquery, err := db.Prepare(dql)\n\tif err != nil {\n\t\treturn errors.Wrapf(err, \"failed to prepare query: %v\", f.Table)\n\t}\n\tdefer query.Close()\n\trows, err := query.Query()\n\tif err != nil {\n\t\treturn errors.Wrapf(err, \"failed to query: %v\", f.Table)\n\t}\n\tcolumns, err := rows.Columns()\n\tif err != nil {\n\t\treturn errors.Wrapf(err, \"failed to discover column: %v\", f.Table)\n\t}\n\t//TODO move to Setup methods\n\tmapper, err := newWriterRowMapper(columns, f.Type.T)\n\tif err != nil {\n\t\treturn errors.WithContext(err, \"creating row mapper\")\n\t}\n\twriter, err := newWriter(f.Driver, f.BatchSize, f.Table, columns)\n\tif err != nil {\n\t\treturn err\n\t}\n\tvar val beam.X\n\tfor iter(&val) {\n\t\tvar row []any\n\t\tvar data map[string]any","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/io/databaseio/database.go#L157-L193","documentation":"Raised when query.Query() fails to execute the prepared `SELECT ... WHERE 1 = 0` schema-probe statement against the target table. The statement was prepared successfully, so the SQL is valid, but executing it failed — typically a connectivity, timeout, or runtime SQL error from the driver. The writer needs the (empty) result set only to read column metadata before doing INSERTs.","triggerScenarios":"Connection dropped or timed out between Prepare and Query; database became unavailable mid-pipeline; driver-level runtime error executing the probe query; the statement was prepared on a pool connection that later went stale.","commonSituations":"Long-running Beam pipelines where idle DB connections are reaped by a firewall/load balancer; transient network blips during bundle execution; database restarts; connection-pool exhaustion causing query execution failures.","solutions":["Check database availability and network connectivity from the pipeline workers.","Retry the pipeline or re-run the failing bundle; transient connection drops are the most common cause.","Adjust DSN connection parameters (timeouts, keepalives) so idle prepared connections aren't dropped.","Inspect the wrapped driver error for the exact execution failure (e.g. 'connection refused', 'too many connections')."],"exampleFix":"// before\ndb, err := sql.Open(driver, dsn) // no timeouts; stale conns fail at Query\n// after\ndb, err := sql.Open(driver, dsn)\ndb.SetConnMaxLifetime(5 * time.Minute) // recycle connections before they go stale","handlingStrategy":"retry","validationCode":"if err := db.PingContext(ctx); err != nil { return fmt.Errorf(\"database unreachable before write: %w\", err) }","typeGuard":null,"tryCatchPattern":"if err != nil {\n    if isTransientNetErr(err) { // e.g. net.Error Timeout, driver 'bad connection'\n        return err // let Beam retry the bundle\n    }\n    return errors.Wrapf(err, \"permanent failure querying table %q\", table)\n}","preventionTips":["Set db.SetConnMaxLifetime below any firewall/load-balancer idle timeout.","Configure DSN keepalive/read-timeout parameters appropriate to the backend.","Monitor database availability and connection-pool limits during pipeline runs.","Prefer retryable bundle semantics for transient connection errors instead of failing the job."],"tags":["database","sql","network","query-execution"],"backgroundTag":"sql-query-failed","analyzedSha":"12126d8942aaf848030c478b4c6a28c6af861c66","analyzedAt":"2026-09-13T01:50:10.254Z","contentChangedAt":"2026-09-13T01:50:10.254Z","schemaVersion":2},"datasetVersion":"2026-09-20T03:17:13.778Z"}