| 28 | func (ASTArray) UseAs() Node { return ASTArray{} } |
| 29 | |
| 30 | func (a ASTArray) ContainsSQL(cfg *SQLGenerator, needle Node) (string, error) { |
| 31 | // If we have no elements in our set, then our needle is never in the set. |
| 32 | if len(a.Value) == 0 { |
| 33 | return "false", nil |
| 34 | } |
| 35 | |
| 36 | // This condition supports any contains function if the needle type is |
| 37 | // the same as the ASTArray element type. |
| 38 | if reflect.TypeOf(a.MyType().UseAs()) != reflect.TypeOf(needle.UseAs()) { |
| 39 | return "ArrayContainsError", xerrors.Errorf("array contains %q: type mismatch (%T, %T)", |
| 40 | a.Source, a.MyType(), needle) |
| 41 | } |
| 42 | |
| 43 | return fmt.Sprintf("%s = ANY(%s)", needle.SQLString(cfg), a.SQLString(cfg)), nil |
| 44 | } |
| 45 | |
| 46 | func (a ASTArray) SQLString(cfg *SQLGenerator) string { |
| 47 | switch a.MyType().UseAs().(type) { |