temporalio/temporal · error

only comparison and "and" expression is supported

Error message

only comparison and "and" expression is supported

What it means

Thrown by gcloud queryParser.convertWhereExpr when the WHERE clause contains an expression type other than ComparisonExpr, AndExpr, or ParenExpr. The GCloud archival visibility parser implements only this limited SQL subset; OR, NOT, arithmetic, and other sqlparser node kinds are unsupported.

Source

Thrown at common/archiver/gcloud/query_parser.go:91

	}

	return parsedQuery, nil
}

func (p *queryParser) convertWhereExpr(expr sqlparser.Expr, parsedQuery *parsedQuery) error {
	if expr == nil {
		return errors.New("where expression is nil")
	}

	switch expr := expr.(type) {
	case *sqlparser.ComparisonExpr:
		return p.convertComparisonExpr(expr, parsedQuery)
	case *sqlparser.AndExpr:
		return p.convertAndExpr(expr, parsedQuery)
	case *sqlparser.ParenExpr:
		return p.convertParenExpr(expr, parsedQuery)
	default:
		return errors.New("only comparison and \"and\" expression is supported")
	}
}

func (p *queryParser) convertParenExpr(parenExpr *sqlparser.ParenExpr, parsedQuery *parsedQuery) error {
	return p.convertWhereExpr(parenExpr.Expr, parsedQuery)
}

func (p *queryParser) convertAndExpr(andExpr *sqlparser.AndExpr, parsedQuery *parsedQuery) error {
	if err := p.convertWhereExpr(andExpr.Left, parsedQuery); err != nil {
		return err
	}
	return p.convertWhereExpr(andExpr.Right, parsedQuery)
}

func (p *queryParser) convertComparisonExpr(compExpr *sqlparser.ComparisonExpr, parsedQuery *parsedQuery) error {
	colName, ok := compExpr.Left.(*sqlparser.ColName)
	if !ok {
		return fmt.Errorf("invalid filter name: %s", sqlparser.String(compExpr.Left))

View on GitHub (pinned to bde624efd1)

Solutions

  1. Rewrite the query using only `=` comparisons, `AND`, and parentheses; OR must be expanded into separate queries.
  2. Replace NOT conditions with their positive comparison equivalent.
  3. If OR semantics are required, use Elasticsearch or SQL visibility instead of the GCloud archival visibility store.
  4. Note ComparisonExpr covers all comparison operators (=, <, >, <=, >=, !=), so range conditions are fine as long as they are joined with AND.

Example fix

// before
q := "WorkflowType = 'pay' OR WorkflowType = 'refund'"
parsed, err := parser.Parse(q) // error: only comparison and "and" expression is supported

// after
// run one query per workflow type, or use ES/SQL visibility
q := "WorkflowType = 'pay' AND StartTime = '2024-01-01T00:00:00Z' AND SearchPrecision = 'Day'"
parsed, err := parser.Parse(q)
Defensive patterns

Strategy: validation

Validate before calling

if strings.Contains(strings.ToLower(query), " or ") || strings.Contains(strings.ToLower(query), "not ") {
	return nil, errors.New("gcloud archival visibility supports only comparisons joined by AND")
}

Prevention

When it happens

Trigger: Parse("WorkflowId = 'x' OR RunId = 'y'") — OrExpr hits the default branch. Same for NOT expressions, function calls, or nested subqueries in the WHERE clause.

Common situations: Users familiar with full SQL or Elasticsearch query syntax write `StartTime > '...' OR CloseTime < '...'` or `NOT WorkflowType = 'x'` against GCloud archival visibility and get this error.

Related errors


AI-assisted analysis of temporalio/temporal@bde624efd1 (2026-09-01). Data as JSON: /api/errors/849a60b884970a60. Report an issue: GitHub.