{"record":{"id":"bbd1ffa216ddc1d2","repo":"SigNoz/signoz","slug":"codeunsupported-bbd1ff","errorCode":"CodeUnsupported","errorMessage":"reserved keyword found in select clause","messagePattern":"reserved keyword found in select clause","errorType":"error_code","errorClass":null,"httpStatus":400,"severity":"error","filePath":"pkg/queryparser/queryfilterextractor/clickhouse_originparser.go","lineNumber":175,"sourceCode":"\t\t\t\t\tfor _, arg := range funcExpr.Params.Items.Items {\n\t\t\t\t\t\tif containsJSONExtractFunction(arg) {\n\t\t\t\t\t\t\thasExcludedExpressions = true\n\t\t\t\t\t\t\treturn false\n\t\t\t\t\t\t}\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t}\n\t\t}\n\t\tif _, ok := node.(*parser.CaseExpr); ok {\n\t\t\thasExcludedExpressions = true\n\t\t\treturn false\n\t\t}\n\t\treturn true\n\t})\n\n\t// If the expression contains reserved keywords, return error\n\tif hasReservedKeyword {\n\t\treturn \"\", errors.New(errors.TypeUnsupported, errors.CodeUnsupported, \"reserved keyword found in select clause\")\n\t}\n\n\t// If the expression contains excluded expressions, return empty string\n\tif hasExcludedExpressions {\n\t\treturn \"\", nil\n\t}\n\n\t// Extract all column names from the expression\n\tcolumns := extractColumns(expr)\n\n\t// If we found exactly one unique column, return it\n\tif len(columns) == 1 {\n\t\treturn columns[0], nil\n\t}\n\n\t// Multiple columns or no columns - return empty string\n\treturn \"\", nil\n}","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/SigNoz/signoz/blob/5069bf80b08f1f00d7e014eccc09902f9871004f/pkg/queryparser/queryfilterextractor/clickhouse_originparser.go#L157-L193","documentation":"The ClickHouse origin-field parser walks the SELECT expressions of a query and rejects the query if it contains reserved SQL keywords. This is a guard against queries whose select clause cannot be safely decomposed for origin-field extraction (used to attribute metrics to their source column).","triggerScenarios":"Calling extractCHOriginFieldFromQuery (query filter extraction pipeline) with a query whose SELECT clause uses reserved keywords such as functions or clauses the extractor does not support.","commonSituations":"Writing custom ClickHouse queries with window functions, CTE keywords, aliases colliding with reserved words, or upgrading the parser so more keywords become rejected.","solutions":["Rewrite the select clause to avoid the reserved keyword (rename aliases, restructure expressions)","Check the parser's reserved keyword list and remove/extend it if the keyword is safe for extraction","Fall back to manual origin-field specification instead of automatic extraction"],"exampleFix":"// before\nSELECT count() AS group FROM samples\n\n// after\nSELECT count() AS sample_count FROM samples","handlingStrategy":"validation","validationCode":"// lint queries before passing to the extractor\nfunc safeForOriginExtraction(q string) bool {\n    upper := strings.ToUpper(q)\n    for _, kw := range []string{\"GROUP\", \"ORDER\", \"HAVING\"} { // per parser's list\n        if strings.Contains(upper, kw) {\n            return false\n        }\n    }\n    return true\n}","typeGuard":null,"tryCatchPattern":"field, err := extractCHOriginFieldFromQuery(q)\nif err != nil && errors.Is(err, errUnsupported) {\n    // fall back to manual origin field\n}","preventionTips":["Keep SELECT clauses simple when relying on automatic origin extraction","Maintain a lint/test that flags reserved keywords in generated queries"],"tags":["go","clickhouse","sql-parsing","reserved-keywords"],"backgroundTag":"sql-parse-unsupported-syntax","analyzedSha":"5069bf80b08f1f00d7e014eccc09902f9871004f","analyzedAt":"2026-08-28T06:22:12.824Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}