ArrayContains return true if the haystack contains all needles.
(ctx *EvalContext, haystack *DArray, needles *DArray)
| 296 | |
| 297 | // ArrayContains return true if the haystack contains all needles. |
| 298 | func 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 | |
| 321 | func initArrayToArrayConcatenation() { |
| 322 | for _, t := range types.Scalar { |
no test coverage detected
searching dependent graphs…