{"record":{"id":"04230f852ccb5a6c","repo":"googleapis/mcp-toolbox","slug":"unable-to-execute-query-w-04230f","errorCode":null,"errorMessage":"unable to execute query: %w","messagePattern":"unable to execute query: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/bigquery/bigquery.go","lineNumber":628,"sourceCode":"\tif params != nil {\n\t\tquery.Parameters = params\n\t}\n\tif connProps != nil {\n\t\tquery.ConnectionProperties = connProps\n\t}\n\tif labels != nil {\n\t\tquery.Labels = labels\n\t}\n\tif s.MaximumBytesBilled > 0 {\n\t\tquery.MaxBytesBilled = s.MaximumBytesBilled\n\t}\n\n\t// This block handles SELECT statements, which return a row set.\n\t// We iterate through the results, convert each row into a map of\n\t// column names to values, and return the collection of rows.\n\tjob, err := query.Run(ctx)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to execute query: %w\", err)\n\t}\n\tit, err := job.Read(ctx)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to read query results: %w\", err)\n\t}\n\n\tout := []any{}\n\tfor s.MaxQueryResultRows <= 0 || len(out) < s.MaxQueryResultRows {\n\t\tvar val []bigqueryapi.Value\n\t\terr = it.Next(&val)\n\t\tif err == iterator.Done {\n\t\t\tbreak\n\t\t}\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"unable to iterate through query results: %w\", err)\n\t\t}\n\t\tschema := it.Schema\n\t\trow := orderedmap.Row{}","sourceCodeStart":610,"sourceCodeEnd":646,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/bigquery/bigquery.go#L610-L646","documentation":"The BigQuery query job could not be started. query.Run(ctx) submits the SQL to BigQuery and creates a job; any API-level rejection (invalid SQL, permission denied, quota, invalid parameters, bytes-billed limits) surfaces here wrapped with this message.","triggerScenarios":"Calling RunSQL via execute-sql style tools when BigQuery rejects the job creation: syntax errors in the statement, caller lacking bigquery.jobs.create, exceeding MaximumBytesBilled limits, rate/quota limits, unknown table/column in a dry-run-validating API, or invalid query parameters.","commonSituations":"Typos or dialect issues in SQL (legacy vs standard SQL), service account missing BigQuery Job User role, billing not enabled on the project, MaxBytesBilled set below the query's scanned bytes, or location mismatch between client and dataset.","solutions":["Read the wrapped Google API error for the exact reason (invalidQuery, accessDenied, billingTierLimitExceeded, etc.) and fix the SQL or permissions accordingly","Grant the caller account roles/bigquery.jobUser (and dataViewer as needed) on the project/dataset","Check the query's estimated bytes against s.MaximumBytesBilled and raise the limit or optimize the query","Ensure query.Location matches the dataset's location"],"exampleFix":"// before\nquery.MaxBytesBilled = 10 * 1024 * 1024 // too low for scan\n// after\nquery.MaxBytesBilled = 0 // unlimited, or a limit above estimated scanned bytes","handlingStrategy":"try-catch","validationCode":"// dry-run to validate before executing\nq := client.Query(statement)\nq.Parameters = params\nq.Location = client.Location\nq.DryRun = true\nif _, err := q.Run(ctx); err != nil {\n    return fmt.Errorf(\"query would fail: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"_, err := src.RunSQL(ctx, client, stmt, \"SELECT\", params, nil, nil)\nif err != nil && strings.Contains(err.Error(), \"unable to execute query\") {\n    var apiErr *googleapi.Error\n    if errors.As(err, &apiErr) && (apiErr.Code == 429 || apiErr.Code >= 500) {\n        return retryWithBackoff(ctx)\n    }\n    return err // non-retryable: fix SQL/permissions\n}","preventionTips":["Validate SQL with a BigQuery dry run before executing","Grant the caller roles/bigquery.jobUser and dataset-level read roles","Set MaximumBytesBilled above expected scan volume to avoid billingTierLimitExceeded","Keep client location in sync with dataset location"],"tags":["bigquery","sql","api-error","permissions"],"backgroundTag":"bigquery-query-execution-failed","analyzedSha":"8cc6e09de2ad7b8bffc77751799585a1401a48eb","analyzedAt":"2026-09-05T01:10:36.887Z","contentChangedAt":"2026-09-05T01:10:36.887Z","schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}