Skip to content

.contains() resolves to IN instead of LIKE when used inside .map on optional string column #282

@kingluscious

Description

@kingluscious

Description

When calling .contains("text") on an unwrapped optional String column inside .map, the generated SQL uses the IN operator instead of LIKE '%text%'. The same .contains() call on a non-optional String column correctly generates LIKE.

Checklist

  • I have determined whether this bug is also reproducible in a vanilla SwiftUI project.
  • If possible, I've reproduced the issue using the main branch of this package.
  • This issue hasn't been addressed in an existing GitHub issue or discussion.

Expected behavior

-- Expected for optional:
WHERE CASE "items"."subtitle" IS NULL WHEN 1 THEN NULL ELSE ("items"."subtitle" LIKE '%red%') END

Actual behavior

WHERE CASE "items"."subtitle" IS NULL WHEN 1 THEN NULL ELSE ('red') IN (("items"."subtitle")) END

Reproducing project

It appears that inside the .map closure, Swift's overload resolution picks a .contains that checks element membership (IN) rather than the string .contains that produces LIKE. Likely because String conforms to both String​Protocol and Query​Expression​<​String> (via Query​Bindable), and the generic context of .map​<​T> tips the type checker toward the wrong overload.

Structured Queries version information

swift-structured-queries 0.31.1

Destination operating system

No response

Xcode version information

Version 26.4 (17E192

Swift Compiler version information

arm64-apple-macosx26.0

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions