{"record":{"id":"a97dfc8e9ab38b50","repo":"apache/beam","slug":"failed-to-run-query-v","errorCode":null,"errorMessage":"failed to run query: %v","messagePattern":"failed to run query: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"sdks/go/pkg/beam/io/databaseio/database.go","lineNumber":85,"sourceCode":"\t// Type is the encoded schema type.\n\tType beam.EncodedType `json:\"type\"`\n}\n\nfunc (f *queryFn) ProcessElement(ctx context.Context, _ []byte, emit func(beam.X)) error {\n\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\tstatement, err := db.PrepareContext(ctx, f.Query)\n\tif err != nil {\n\t\treturn errors.Wrapf(err, \"failed to prepare query: %v\", f.Query)\n\t}\n\tdefer statement.Close()\n\trows, err := statement.QueryContext(ctx)\n\tif err != nil {\n\t\treturn errors.Wrapf(err, \"failed to run query: %v\", f.Query)\n\t}\n\tdefer rows.Close()\n\tvar mapper rowMapper\n\tvar columns []string\n\tfor rows.Next() {\n\t\treflectRow := reflect.New(f.Type.T)\n\t\trow := reflectRow.Interface() // row : *T\n\t\tif mapper == nil {\n\t\t\tcolumns, err = rows.Columns()\n\t\t\tif err != nil {\n\t\t\t\treturn err\n\t\t\t}\n\t\t\tcolumnsTypes, _ := rows.ColumnTypes()\n\t\t\tif mapper, err = newQueryMapper(columns, columnsTypes, f.Type.T); err != nil {\n\t\t\t\treturn errors.WithContext(err, \"creating rowValues mapper\")\n\t\t\t}\n\t\t}\n\t\trowValues, err := mapper(reflectRow)","sourceCodeStart":67,"sourceCodeEnd":103,"githubUrl":"https://github.com/apache/beam/blob/12126d8942aaf848030c478b4c6a28c6af861c66/sdks/go/pkg/beam/io/databaseio/database.go#L67-L103","documentation":"The prepared statement is executed with statement.QueryContext(ctx); if execution fails, the error is wrapped as \"failed to run query: %v\" with the query text. Unlike prepare, this covers runtime execution failures: permission errors, constraint/data issues, server-side cancellation, and context timeouts during execution.","triggerScenarios":"statement.QueryContext(ctx) returns an error: query execution rejected by the server (insufficient privileges, deadlock, lock timeout), context canceled/expired mid-query, or connection loss during execution.","commonSituations":"Querying tables the pipeline's DB user cannot read; long-running queries hitting context deadlines on slow networks; database failovers; row-level security blocking access.","solutions":["Run the query manually with the same DB credentials to reproduce and read the server error.","Grant SELECT privileges on the referenced tables to the pipeline's database user.","Increase the context timeout / pipeline timeouts if the query legitimately runs long, or optimize the query (indexes, filters).","Check DB server logs for lock contention, crashes, or connection limits at the failure time."],"exampleFix":null,"handlingStrategy":"retry","validationCode":null,"typeGuard":null,"tryCatchPattern":"rows, err := stmt.QueryContext(ctx)\nif err != nil {\n\tif ctx.Err() != nil { return fmt.Errorf(\"query canceled/timed out: %w\", ctx.Err()) }\n\treturn fmt.Errorf(\"failed to run query: %w\", err)\n}","preventionTips":["Grant SELECT on needed tables to the pipeline DB user.","Set realistic context deadlines and index hot query paths.","Alert on DB failover/lock events during pipeline windows."],"tags":["database","sql","query","go"],"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"}