Skip to content

[Sqlite]: Skip undefined JOIN ON / ORDER BY / GROUP BY from sql.if(false) - #6177

Open
bun-unsafe wants to merge 1 commit into
drizzle-team:mainfrom
bun-unsafe:sqlite/if-false-undefined-holes
Open

[Sqlite]: Skip undefined JOIN ON / ORDER BY / GROUP BY from sql.if(false)#6177
bun-unsafe wants to merge 1 commit into
drizzle-team:mainfrom
bun-unsafe:sqlite/if-false-undefined-holes

Conversation

@bun-unsafe

@bun-unsafe bun-unsafe commented Aug 25, 2026

Copy link
Copy Markdown

Summary

sql.if(false) returns undefined. SQLite already drops that in WHERE / HAVING, but:

  • leftJoin / innerJoin kept the JOIN and dropped ON → cartesian product (2 rows became 4 in a 2×2 fixture)
  • orderBy / groupBy kept an empty list slot → ORDER BY , col / GROUP BY , col (SQLite near ",": syntax error)

This patch skips a non-cross JOIN when on is undefined (rolling back field/nullability/used-table mutations), and filters undefined entries in ORDER BY / GROUP BY (builder + dialect).

Test plan

  • drizzle-orm/tests/sqlite-if-undefined.test.ts (QueryBuilder toSQL)
  • cd integration-tests && pnpm test if Docker is available

.sql.if(false) returns undefined. WHERE already drops it, but JOIN kept
the table without ON (cartesian product) and ORDER BY/GROUP BY emitted a
leading comma (syntax error).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant