Skip to content

db-postgres: OR filters on two text fields in the same block throw a duplicate JOIN alias error #19459

Open

Description

@cp7553479

Describe the Bug

With PostgreSQL and the default relational Blocks storage, two valid text paths under the same Block type work independently but throw when combined with or in one Local API find. This also affects Admin List Search if both paths are in admin.listSearchableFields, since it combines the fields with or.

Link to the code that reproduces this issue

https://gist.github.com/cp7553479/aed86834da2b6111eeb02dc984185848

Reproduction Steps

  1. Save the linked script as repro.mjs in an empty directory and install [email protected] and @payloadcms/[email protected].
  2. Point DATABASE_URL at a new disposable PostgreSQL database (the script uses schema push). Run NODE_ENV=development DATABASE_URL='<disposable-postgres-url>' node repro.mjs.
  3. The script creates one article with a card block and runs three queries: layout.heading, layout.caption, and { or: [headingCondition, captionCondition] }.

Expected: all three queries return totalDocs: 1.

Actual:

{"layout.heading":{"like":"needle"}} 1
{"layout.caption":{"like":"needle"}} 1
Error: Alias "articles_blocks_card" is already used in this query

The same script reproduces on 4.0.0-beta.7 with both dependencies set to that version and a fresh database. No Next.js or Admin setup is needed.

The Blocks path resolver appends the parent block join for each matched path. Both paths resolve to the same table, so Drizzle throws when building the second join. This is distinct from #8517 / #8823, which addressed normal Array fields.

Which area(s) are affected?

db: postgres

Environment Info

  • Payload and @payloadcms/db-postgres: 3.93.0 and 4.0.0-beta.7, tested separately
  • PostgreSQL: 17.11
  • Node.js: 24.21.0
  • Next.js: not used (standalone Local API reproduction)

Activity

  1. added
    db: postgres
    on Nov 9, 2026
  2. added a commit that references this issue on Nov 10, 2026
    328ff08
  3. muhammad-wasif-code commented on Nov 10, 2026

    @muhammad-wasif-code
    Contributor

    Opened a PR that dedupes relational Blocks joins when the same block table is referenced by multiple fields in one or/and query: #19477

    It includes a regression test covering single-field, or, and and queries.

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: postgres

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions