{"record":{"id":"2dbe672542f172fc","repo":"googleapis/mcp-toolbox","slug":"unable-to-parse-row-w-2dbe67","errorCode":null,"errorMessage":"unable to parse row: %w","messagePattern":"unable to parse row: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"internal/sources/cloudsqlpg/cloud_sql_pg.go","lineNumber":131,"sourceCode":"\nfunc (s *Source) PostgresPool() *pgxpool.Pool {\n\treturn s.Pool\n}\n\nfunc (s *Source) RunSQL(ctx context.Context, statement string, params []any) (any, error) {\n\tstatement = sqlcommenter.PrependComment(ctx, statement, SourceType, s.SQLCommenter)\n\tresults, err := s.PostgresPool().Query(ctx, statement, params...)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to execute query: %w\", err)\n\t}\n\tdefer results.Close()\n\n\tfields := results.FieldDescriptions()\n\tout := []any{}\n\tfor results.Next() {\n\t\tvalues, 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\trow := orderedmap.Row{}\n\t\tfor i, f := range fields {\n\t\t\tval := sources.NormalizeValue(values[i], f.DataTypeOID)\n\t\t\trow.Add(f.Name, val)\n\t\t}\n\t\tout = append(out, row)\n\t}\n\t// this will catch actual query execution errors\n\tif err := results.Err(); err != nil {\n\t\treturn nil, fmt.Errorf(\"unable to execute query: %w\", err)\n\t}\n\treturn out, nil\n}\n\nfunc getConnectionConfig(ctx context.Context, user, pass, dbname string, readOnly bool) (string, bool, error) {\n\tuserAgent, err := util.UserAgentFromContext(ctx)\n\tif err != nil {","sourceCodeStart":113,"sourceCodeEnd":149,"githubUrl":"https://github.com/googleapis/mcp-toolbox/blob/8cc6e09de2ad7b8bffc77751799585a1401a48eb/internal/sources/cloudsqlpg/cloud_sql_pg.go#L113-L149","documentation":"RunSQL in the cloud-sql-postgres source wraps any error pgx returns while decoding a result row into Go values. After a query succeeds and iteration begins, results.Values() decodes each column; if a value cannot be scanned into the expected type (or a protocol/timeout error interrupts iteration), the row parse fails and this error is returned. It is distinct from query execution errors, which are caught after the loop via results.Err().","triggerScenarios":"Calling RunSQL (directly or via the execute-sql tool) where a result row fails to decode: column types pgx cannot map to Go values, data corruption mid-stream, cancelled context during iteration, or a connection drop while fetching rows.","commonSituations":"Selecting unusual column types (e.g. custom composite/enum OIDs, huge blobs) that fail normalization; an LLM-issued query returning exotic types; network interruption or statement timeout while streaming rows; running on a connection killed by Cloud SQL idle timeout mid-result.","solutions":["Inspect the wrapped pgx error to identify which column/type failed; cast the problematic column in SQL (e.g. col::text) so it decodes to a simple type.","Check the context deadline/cancellation and network stability; increase timeouts if rows are being cut off mid-stream.","Update the pgx library version in case of a known decoding bug for the offending type OID.","If decoding custom types, avoid selecting them or use a view that coerces them to supported types."],"exampleFix":"// before: SELECT custom_composite_col FROM my_table\n// after: SELECT custom_composite_col::text AS custom_composite_col FROM my_table","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"out, err := source.RunSQL(ctx, stmt, params)\nif err != nil {\n    var pgErr *pgconn.PgError\n    if errors.As(err, &pgErr) {\n        // inspect pgErr.Message / pgErr.Code for the decoding cause\n    }\n    return fmt.Errorf(\"row decode failed: %w\", err)\n}","preventionTips":["Cast exotic columns to ::text or scalar types in generated SQL","Keep pgx/v5 up to date for type-decoding fixes","Set generous context timeouts for large result sets","Test queries returning all column types of your schema"],"tags":["postgres","row-decoding","query-execution","pgx"],"backgroundTag":"row-decode-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"}