{"record":{"id":"e129e989777c3197","repo":"SigNoz/signoz","slug":"error-while-scanning-rows-s","errorCode":null,"errorMessage":"error while scanning rows: %s","messagePattern":"error while scanning rows: (.+?)","errorType":"exception","errorClass":null,"httpStatus":500,"severity":"error","filePath":"pkg/query-service/app/clickhouseReader/reader.go","lineNumber":3128,"sourceCode":"\tif reductionEnabled {\n\t\tquery = fmt.Sprintf(\"SELECT arrayJoin(tagKeys) AS distinctTagKey FROM (SELECT JSONExtractKeys(labels) AS tagKeys FROM %s.%s WHERE metric_name=$1 AND unix_milli >= $2 GROUP BY tagKeys UNION ALL SELECT JSONExtractKeys(labels) AS tagKeys FROM %s.%s WHERE metric_name=$1 AND unix_milli >= $2 GROUP BY tagKeys) WHERE distinctTagKey ILIKE $3 AND distinctTagKey NOT LIKE '\\\\_\\\\_%%' GROUP BY distinctTagKey\", signozMetricDBName, signozTSTableNameV41Day, signozMetricDBName, signozTSTableNameV4Reduced)\n\t} else {\n\t\tquery = fmt.Sprintf(\"SELECT arrayJoin(tagKeys) AS distinctTagKey FROM (SELECT JSONExtractKeys(labels) AS tagKeys FROM %s.%s WHERE metric_name=$1 AND unix_milli >= $2 GROUP BY tagKeys) WHERE distinctTagKey ILIKE $3 AND distinctTagKey NOT LIKE '\\\\_\\\\_%%' GROUP BY distinctTagKey\", signozMetricDBName, signozTSTableNameV41Day)\n\t}\n\tif req.Limit != 0 {\n\t\tquery = query + fmt.Sprintf(\" LIMIT %d;\", req.Limit)\n\t}\n\trows, err = r.db.Query(ctx, query, req.AggregateAttribute, common.PastDayRoundOff(), fmt.Sprintf(\"%%%s%%\", req.SearchText))\n\tif err != nil {\n\t\tr.logger.Error(\"Error while executing query\", errorsV2.Attr(err))\n\t\treturn nil, fmt.Errorf(\"error while executing query: %s\", err.Error())\n\t}\n\tdefer rows.Close()\n\n\tvar attributeKey string\n\tfor rows.Next() {\n\t\tif err := rows.Scan(&attributeKey); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"error while scanning rows: %s\", err.Error())\n\t\t}\n\t\tkey := v3.AttributeKey{\n\t\t\tKey:      attributeKey,\n\t\t\tDataType: v3.AttributeKeyDataTypeString, // https://github.com/OpenObservability/OpenMetrics/blob/main/proto/openmetrics_data_model.proto#L64-L72.\n\t\t\tType:     v3.AttributeKeyTypeTag,\n\t\t\tIsColumn: false,\n\t\t}\n\t\tresponse.AttributeKeys = append(response.AttributeKeys, key)\n\t}\n\n\treturn &response, nil\n}\n\nfunc (r *ClickHouseReader) GetMeterAttributeKeys(ctx context.Context, req *v3.FilterAttributeKeyRequest) (*v3.FilterAttributeKeyResponse, error) {\n\tctx = ctxtypes.NewContextWithCommentVals(ctx, map[string]string{\n\t\tinstrumentationtypes.TelemetrySignal:  telemetrytypes.SignalMetrics.StringValue(),\n\t\tinstrumentationtypes.CodeNamespace:    \"clickhouse-reader\",\n\t\tinstrumentationtypes.CodeFunctionName: \"GetMeterAttributeKeys\",","sourceCodeStart":3110,"sourceCodeEnd":3146,"githubUrl":"https://github.com/SigNoz/signoz/blob/5069bf80b08f1f00d7e014eccc09902f9871004f/pkg/query-service/app/clickhouseReader/reader.go#L3110-L3146","documentation":"Iterating the metric attribute-key query results, rows.Scan(&attributeKey) failed because a row could not be deserialized into a single string. Indicates the result column is not a plain string for that row (Nullable, wrong column count due to schema drift, or driver type mapping change).","triggerScenarios":"The attribute-key SELECT runs but its result column type doesn't match string: e.g. Nullable(String) rows with NULLs, or a redefined view returning extra columns.","commonSituations":"Schema drift after partial upgrades; NULL tag keys in noisy data; clickhouse-go version changes affecting LowCardinality(String) scanning.","solutions":["Run the logged query manually and inspect result column types/NULLs","Align query-service and schema versions","Scan into sql.NullString and skip invalid rows","Report/check driver compatibility if it began after a dependency upgrade"],"exampleFix":"// before\nvar attributeKey string\nif err := rows.Scan(&attributeKey); err != nil { ... }\n\n// after\nvar attributeKey sql.NullString\nif err := rows.Scan(&attributeKey); err != nil { ... }\nif !attributeKey.Valid { continue }","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"for rows.Next() {\n  var key sql.NullString\n  if err := rows.Scan(&key); err != nil { logger.Warn(...); continue }\n  if !key.Valid { continue }\n  ...\n}","preventionTips":["Scan into sql.NullString to tolerate NULL tag keys","Keep schema and app versions aligned; integration-test against real schema"],"tags":["clickhouse","metrics","attributes","row-scan"],"backgroundTag":"row-scan-type-mismatch","analyzedSha":"5069bf80b08f1f00d7e014eccc09902f9871004f","analyzedAt":"2026-08-28T06:22:12.824Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}