ArrayContains return true if the haystack contains all needles.
( ctx context.Context, cmpCtx CompareContext, haystack *DArray, needles *DArray, )
| 356 | |
| 357 | // ArrayContains return true if the haystack contains all needles. |
| 358 | func 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. |
nothing calls this directly
no test coverage detected
searching dependent graphs…