{"record":{"id":"a03d171351eda4c2","repo":"temporalio/temporal","slug":"searchprecision-is-required-when-searching-for-a-s-a03d17","errorCode":null,"errorMessage":"SearchPrecision is required when searching for a StartTime or CloseTime","messagePattern":"SearchPrecision is required when searching for a StartTime or CloseTime","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"common/archiver/s3store/query_parser.go","lineNumber":75,"sourceCode":"\tif err != nil {\n\t\treturn nil, err\n\t}\n\twhereExpr := stmt.(*sqlparser.Select).Where.Expr\n\tparsedQuery := &parsedQuery{}\n\tif err := p.convertWhereExpr(whereExpr, parsedQuery); err != nil {\n\t\treturn nil, err\n\t}\n\tif parsedQuery.workflowID == nil && parsedQuery.workflowType == nil {\n\t\treturn nil, errors.New(\"WorkflowId or WorkflowType is required in query\")\n\t}\n\tif parsedQuery.workflowID != nil && parsedQuery.workflowType != nil {\n\t\treturn nil, errors.New(\"only one of WorkflowId or WorkflowType can be specified in a query\")\n\t}\n\tif parsedQuery.closeTime != nil && parsedQuery.startTime != nil {\n\t\treturn nil, errors.New(\"only one of StartTime or CloseTime can be specified in a query\")\n\t}\n\tif (parsedQuery.closeTime != nil || parsedQuery.startTime != nil) && parsedQuery.searchPrecision == nil {\n\t\treturn nil, errors.New(\"SearchPrecision is required when searching for a StartTime or CloseTime\")\n\t}\n\n\tif parsedQuery.closeTime == nil && parsedQuery.startTime == nil && parsedQuery.searchPrecision != nil {\n\t\treturn nil, errors.New(\"SearchPrecision requires a StartTime or CloseTime\")\n\t}\n\treturn parsedQuery, nil\n}\n\nfunc (p *queryParser) convertWhereExpr(expr sqlparser.Expr, parsedQuery *parsedQuery) error {\n\tif expr == nil {\n\t\treturn errors.New(\"where expression is nil\")\n\t}\n\n\tswitch expr := expr.(type) {\n\tcase *sqlparser.ComparisonExpr:\n\t\treturn p.convertComparisonExpr(expr, parsedQuery)\n\tcase *sqlparser.AndExpr:\n\t\treturn p.convertAndExpr(expr, parsedQuery)","sourceCodeStart":57,"sourceCodeEnd":93,"githubUrl":"https://github.com/temporalio/temporal/blob/bde624efd13fbd3843654058db6d9c716166318b/common/archiver/s3store/query_parser.go#L57-L93","documentation":"When a time filter (StartTime or CloseTime) is present, the archiver needs SearchPrecision (Day|Hour|Minute|Second) to compute the time window over which archived files are scanned. Parse returns this error if a time predicate exists but no SearchPrecision predicate was parsed.","triggerScenarios":"Calling Parse with \"WorkflowId = 'w1' AND StartTime > '2024-01-01T00:00:00Z'\" and no \"SearchPrecision = '...'\" comparison in the WHERE clause.","commonSituations":"Users unaware the archival query dialect requires SearchPrecision; query builders that treat SearchPrecision as optional; migrating queries from SQL visibility which has no such requirement.","solutions":["Add \"AND SearchPrecision = '<Day|Hour|Minute|Second>'\" to the query, matching the time field used.","Choose precision loosely (Day) to widen the scan window if unsure of exact times.","Update query-building code to always emit SearchPrecision alongside any StartTime/CloseTime filter."],"exampleFix":"// before\nparser.Parse(\"WorkflowId = 'w1' AND CloseTime > '2024-01-01'\")\n// after\nparser.Parse(\"WorkflowId = 'w1' AND CloseTime > '2024-01-01' AND SearchPrecision = 'Day'\")","handlingStrategy":"validation","validationCode":"validPrecisions := map[string]bool{\"Day\": true, \"Hour\": true, \"Minute\": true, \"Second\": true}\nif (strings.Contains(query, \"StartTime\") || strings.Contains(query, \"CloseTime\")) &&\n    !strings.Contains(query, \"SearchPrecision\") {\n    return errors.New(\"SearchPrecision is required with a time filter\")\n}","typeGuard":null,"tryCatchPattern":"pq, err := parser.Parse(query)\nif err != nil {\n    if strings.Contains(err.Error(), \"SearchPrecision is required\") {\n        return nil, status.Error(codes.InvalidArgument, \"add SearchPrecision (Day|Hour|Minute|Second) to your time-filtered archival query\")\n    }\n    return nil, err\n}","preventionTips":["Have query builders auto-append SearchPrecision whenever StartTime/CloseTime is present.","Default to \"Day\" precision when the user hasn't specified one.","Restrict SearchPrecision values to the four allowed constants."],"tags":["go","archival","query-validation","s3store"],"backgroundTag":"missing-required-query-parameter","analyzedSha":"bde624efd13fbd3843654058db6d9c716166318b","analyzedAt":"2026-09-01T07:18:39.080Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}