{"record":{"id":"469199c2b1f5047c","repo":"SigNoz/signoz","slug":"error-in-processing-sql-query","errorCode":null,"errorMessage":"error in processing sql query","messagePattern":"error in processing sql query","errorType":"exception","errorClass":null,"httpStatus":500,"severity":"error","filePath":"pkg/query-service/app/clickhouseReader/reader.go","lineNumber":283,"sourceCode":"\tif query.Stats != \"\" {\n\t\tqs = stats.NewQueryStats(qry.Stats())\n\t}\n\n\tqry.Close()\n\treturn res, &qs, nil\n}\n\nfunc (r *ClickHouseReader) GetServicesList(ctx context.Context) (*[]string, error) {\n\tctx = ctxtypes.NewContextWithCommentVals(ctx, map[string]string{\n\t\tinstrumentationtypes.TelemetrySignal:  telemetrytypes.SignalTraces.StringValue(),\n\t\tinstrumentationtypes.CodeNamespace:    \"clickhouse-reader\",\n\t\tinstrumentationtypes.CodeFunctionName: \"GetServicesList\",\n\t})\n\n\tservices := []string{}\n\trows, err := r.db.Query(ctx, fmt.Sprintf(`SELECT DISTINCT resource_string_service$$name FROM %s.%s WHERE ts_bucket_start > (toUnixTimestamp(now() - INTERVAL 1 DAY) - 1800) AND toDate(timestamp) > now() - INTERVAL 1 DAY`, r.TraceDB, r.traceTableName))\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"error in processing sql query\")\n\t}\n\n\tdefer rows.Close()\n\tfor rows.Next() {\n\t\tvar serviceName string\n\t\tif err := rows.Scan(&serviceName); err != nil {\n\t\t\treturn &services, err\n\t\t}\n\t\tservices = append(services, serviceName)\n\t}\n\n\treturn &services, nil\n}\n\nfunc (r *ClickHouseReader) GetTopLevelOperations(ctx context.Context, start, end time.Time, services []string) (*map[string][]string, *model.ApiError) {\n\tctx = ctxtypes.NewContextWithCommentVals(ctx, map[string]string{\n\t\tinstrumentationtypes.TelemetrySignal:  telemetrytypes.SignalTraces.StringValue(),\n\t\tinstrumentationtypes.CodeNamespace:    \"clickhouse-reader\",","sourceCodeStart":265,"sourceCodeEnd":301,"githubUrl":"https://github.com/SigNoz/signoz/blob/5069bf80b08f1f00d7e014eccc09902f9871004f/pkg/query-service/app/clickhouseReader/reader.go#L265-L301","documentation":"Error returned by GetServicesList when the ClickHouse query for distinct service names over the last day fails. The underlying err is discarded (not wrapped), so the message is generic; the real cause appears only in surrounding logs/traces.","triggerScenarios":"Calling getServicesList / the services list API when r.db.Query against the traces table (SIGNOZ_TRACES_DB.<traces table>) fails: bad connection, missing table, syntax issues after schema drift.","commonSituations":"ClickHouse down or misconfigured (wrong TraceDB/table name from env), cold start where traces tables don't exist yet, upgrade where traceTableName changed, or CH overload.","solutions":["Check query-service logs/traces at the same timestamp for the underlying CH error","Verify CLICKHOUSE_URL/trace DB and table config match the actual ClickHouse schema","Confirm traces tables exist and migrations ran","Fix ClickHouse health/resources, then retry"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":"// Pre-flight CH and table checks\nif !chHealthy(ctx) || !tableExists(ctx, ch, r.TraceDB, r.traceTableName) {\n    return fmt.Errorf(\"traces store unavailable\")\n}","typeGuard":"func isServicesListErr(err error) bool {\n    return err != nil && strings.Contains(err.Error(), \"error in processing sql query\")\n}","tryCatchPattern":"svc, err := reader.GetServicesList(ctx)\nif isServicesListErr(err) {\n    logChDiagnostics() // real cause only in logs\n    return []string{}, err\n}","preventionTips":["Monitor ClickHouse availability from query-service","Validate TraceDB/traceTableName env config at startup","Complete CH migrations before serving traffic"],"tags":["clickhouse","traces","services","database"],"backgroundTag":"database-query-failed","analyzedSha":"5069bf80b08f1f00d7e014eccc09902f9871004f","analyzedAt":"2026-08-28T06:22:12.824Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}