drizzle-team / drizzle-orm

Headless TypeScript ORM with a head. Runs on Node, Bun and Deno. Lives on the Edge and yes, it's a JavaScript ORM too 😅
https://orm.drizzle.team
Apache License 2.0
24.68k stars 651 forks source link

[BUG]: `for("update", { noWait: true })` yields invalid SQL: `syntax error at or near "no"` #3554

Open jelder opened 1 week ago

jelder commented 1 week ago

Report hasn't been filed before.

What version of drizzle-orm are you using?

0.23.0

What version of drizzle-kit are you using?

0.32.1-848e136

Other packages

No response

Describe the Bug

Given something like this, where tx is a Drizzle transaction.

  tx.select().from(widgets).for("update", { noWait: true }),

The resulting SQL looks like

select * from widgets for update no wait;

That will result in the error syntax error at or near "no" because Postgres spells this option as a single word:

select * from widgets for update nowait;

This is confusing because the other option here is spelled as two words:

select * from widgets for update skip locked;

Fortunately this can be fixed by simply removing this space: https://github.com/drizzle-team/drizzle-orm/blob/2677718bf98835b8ec313d0f3bf2b921e795e7c1/drizzle-orm/src/pg-core/dialect.ts#L391-L392

Relevant Postgres documentation: https://www.postgresql.org/docs/16/sql-select.html#:~:text=The%20locking%20clause%20has,%5B%2C%20...%5D%20%5D%20%5B%20NOWAIT%20%7C%20SKIP%20LOCKED%20%5D