MCPcopy Create free account
hub / github.com/cockroachdb/cockroachdb-parser / ArrayContains

Function ArrayContains

pkg/sql/sem/tree/eval.go:358–383  ·  view source on GitHub ↗

ArrayContains return true if the haystack contains all needles.

(
	ctx context.Context, cmpCtx CompareContext, haystack *DArray, needles *DArray,
)

Source from the content-addressed store, hash-verified

356
357// ArrayContains return true if the haystack contains all needles.
358func ArrayContains(
359 ctx context.Context, cmpCtx CompareContext, haystack *DArray, needles *DArray,
360) (*DBool, error) {
361 if !haystack.ParamTyp.Equivalent(needles.ParamTyp) {
362 return DBoolFalse, pgerror.New(pgcode.DatatypeMismatch, "cannot compare arrays with different element types")
363 }
364 for _, needle := range needles.Array {
365 // Nulls don't compare to each other in @> syntax.
366 if needle == DNull {
367 return DBoolFalse, nil
368 }
369 var found bool
370 for _, hay := range haystack.Array {
371 if cmp, err := needle.Compare(ctx, cmpCtx, hay); err != nil {
372 return DBoolFalse, err
373 } else if cmp == 0 {
374 found = true
375 break
376 }
377 }
378 if !found {
379 return DBoolFalse, nil
380 }
381 }
382 return DBoolTrue, nil
383}
384
385// ArrayOverlaps return true if there is even one element
386// common between the left and right arrays.

Callers

nothing calls this directly

Calls 3

NewFunction · 0.92
EquivalentMethod · 0.80
CompareMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…