Skip to content

not_like does not match partial values on SQL adapters #19167

Open

Description

@saita-teppei

Describe the Bug

On the SQL adapters, the not_like operator does not exclude documents whose value contains the given string. It only excludes documents whose value is exactly equal to it, so it behaves like a case-insensitive not_equals.

await payload.create({ collection: 'posts', data: { title: 'hello world' } })
await payload.create({ collection: 'posts', data: { title: 'goodbye' } })

const { docs } = await payload.find({
  collection: 'posts',
  where: { title: { not_like: 'hello' } },
})
// Expected: ['goodbye']
// Actual (SQLite / D1 / Postgres): ['hello world', 'goodbye']

The MongoDB adapter handles this as expected: it splits the value into words and excludes documents that contain any of them ($and of $not: { $regex: word, $options: 'i' }), i.e. the negation of like. #11326, which added not_like, also describes it as "just as a negative to like".

Cause

In packages/drizzle/src/queries/parseParams.ts, like has its own branch that wraps every word in %...%. There is no equivalent branch for not_like, so it falls through to sanitizeQueryValue and adapter.operators.not_like(column, value) is called with the raw value. The resulting SQL is NOT LIKE 'hello' (NOT ILIKE on Postgres) without wildcards.

The existing test should query not_like on value in test/fields/int.spec.ts only uses an exact value (not_like: 'cat-unique-test'), so it passes despite this.

The same code is present on both 3.x and main.

Link to the code that reproduces this issue

https://github.com/saita-teppei/payload/tree/repro/not-like-partial

Reproduction Steps

  1. Check out the repro/not-like-partial branch (based on 3.x). It only adds one test to test/_community/int.spec.ts, using the existing posts collection.
  2. Run pnpm install.
  3. Run pnpm test:int:sqlite _community.
  4. The test not_like should exclude documents that contain the value fails:
    AssertionError: expected [ 'goodbye', 'hello world', …(3) ] to not include 'hello world'

Which area(s) are affected?

db: sqlite, db: d1-sqlite, db: postgres

Environment Info

Binaries:
  Node: 24.13.0
Relevant Packages:
  payload: 3.92.1
  next: 16.3.3
  @payloadcms/db-d1-sqlite: 3.92.1
  @payloadcms/drizzle: 3.92.1
  @payloadcms/graphql: 3.92.1
  @payloadcms/richtext-lexical: 3.92.1
  react: 19.2.6
  react-dom: 19.2.6
Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Pro

Also reproduced on the 3.x branch of this repository (commit 8bbd52e) with PAYLOAD_DATABASE=sqlite.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugPayload OSSdb: d1-sqlitedb: postgresdb: sqlite

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions