{"record":{"id":"bc1d7438c7378894","repo":"googleapis/mcp-toolbox","slug":"unable-to-execute-query-w-bc1d74","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/yugabytedb/yugabytedb.go","lineNumber":110,"sourceCode":"\treturn false\n}\n\nfunc (s *Source) SourceType() string {\n\treturn SourceType\n}\n\nfunc (s *Source) ToConfig() sources.SourceConfig {\n\treturn s.Config\n}\n\nfunc (s *Source) YugabyteDBPool() *pgxpool.Pool {\n\treturn s.Pool\n}\n\nfunc (s *Source) RunSQL(ctx context.Context, statement string, params []any) (any, error) {\n\tresults, err := s.YugabyteDBPool().Query(ctx, statement, params...)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to execute query: %w\", err)\n\t}\n\n\tfields := results.FieldDescriptions()\n\n\tout := []any{}\n\tfor results.Next() {\n\t\tv, err := results.Values()\n\t\tif err != nil {\n\t\t\treturn nil, fmt.Errorf(\"unable to parse row: %w\", err)\n\t\t}\n\t\tvMap := make(map[string]any)\n\t\tfor i, f := range fields {\n\t\t\tval := sources.NormalizeValue(v[i], f.DataTypeOID)\n\t\t\tvMap[f.Name] = val\n\t\t}\n\t\tout = append(out, vMap)\n\t}\n","sourceCodeStart":92,"sourceCodeEnd":128,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/yugabytedb/yugabytedb.go#L92-L128","documentation":"YugabyteDB Source.RunSQL executes the statement via the pool's Query; if pgx returns an error issuing the query (SQL syntax error, missing relation, permission denied, cancelled context, connection dropped mid-query), it is wrapped as 'unable to execute query: %w'. The pool connected fine; the failure is at query execution time.","triggerScenarios":"RunSQL invoked with a statement that fails server-side: syntax error, referencing a nonexistent table/column, insufficient privileges, parameter count/type mismatch, statement timeout, or context cancellation while running.","commonSituations":"LLM agent generating invalid SQL against Yugabyte schemas; querying tables that don't exist in the configured database; read-only user attempting writes; long queries hitting timeouts; parameter placeholders count not matching provided params.","solutions":["Fix the SQL syntax and verify table/column names exist in the target database","Check the database user has privileges for the operation (SELECT/INSERT/etc.)","Ensure the number and types of parameters match the placeholders in the statement","Test the statement directly with 'ysqlsh' or 'psql' to see the raw server error","Read the wrapped '%w' cause for the exact Postgres error code"],"exampleFix":"// before\nSELECT * FROM order WHERE id = $1\n// after (orders table, correct name)\nSELECT * FROM orders WHERE id = $1","handlingStrategy":"try-catch","validationCode":"// Basic client-side checks before invoking the tool\nif (typeof statement !== \"string\" || statement.trim() === \"\")\n  throw new Error(\"statement must be a non-empty SQL string\");\nif (statement.includes(\"order \")) console.warn(\"verify table names exist in the database\");","typeGuard":null,"tryCatchPattern":"try {\n  const result = await runYugabyteSQL(statement, params);\n} catch (err) {\n  const cause = err.cause ?? err;\n  if (/syntax error|does not exist|permission denied/i.test(String(cause))) {\n    console.error(\"SQL failed server-side:\", cause.message);\n    // fix statement or permissions, then retry once\n  }\n  throw err;\n}","preventionTips":["Test generated SQL in ysqlsh/psql against the target schema before shipping prompts","Grant the configured database user only the privileges it needs, and know what they are","Match parameter count/types to placeholders exactly","Set sensible statement timeouts and keep queries within them"],"tags":["yugabytedb","sql","query-execution","postgres"],"backgroundTag":"sql-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"}