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

Function ArrayContains

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

ArrayContains return true if the haystack contains all needles.

(ctx *EvalContext, haystack *DArray, needles *DArray)

Source from the content-addressed store, hash-verified

296
297// ArrayContains return true if the haystack contains all needles.
298func ArrayContains(ctx *EvalContext, haystack *DArray, needles *DArray) (*DBool, error) {
299 if !haystack.ParamTyp.Equivalent(needles.ParamTyp) {
300 return DBoolFalse, pgerror.New(pgcode.DatatypeMismatch, "cannot compare arrays with different element types")
301 }
302 for _, needle := range needles.Array {
303 // Nulls don't compare to each other in @> syntax.
304 if needle == DNull {
305 return DBoolFalse, nil
306 }
307 var found bool
308 for _, hay := range haystack.Array {
309 if needle.Compare(ctx, hay) == 0 {
310 found = true
311 break
312 }
313 }
314 if !found {
315 return DBoolFalse, nil
316 }
317 }
318 return DBoolTrue, nil
319}
320
321func initArrayToArrayConcatenation() {
322 for _, t := range types.Scalar {

Callers 1

eval.goFile · 0.85

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…