Skip to content

fix(docs): correct MSSQL insert output() call order#660

Open
sleitor wants to merge 1 commit intodrizzle-team:mainfrom
sleitor:fix-5472-mssql-insert-output
Open

fix(docs): correct MSSQL insert output() call order#660
sleitor wants to merge 1 commit intodrizzle-team:mainfrom
sleitor:fix-5472-mssql-insert-output

Conversation

@sleitor
Copy link

@sleitor sleitor commented Mar 14, 2026

Summary

Fixes drizzle-team/drizzle-orm#5472

The insert.mdx docs show .output() called after .values(), which throws a runtime error. Per MSSQL SQL syntax (and the Drizzle API implementation), OUTPUT must come before VALUES:

-- MSSQL SQL structure:
INSERT INTO users OUTPUT INSERTED.id VALUES ('Dan')

This is confirmed by maintainer @AleksandrSherman: "The use of the output clause in mssql is based directly on the official mssql documentation... But it seems that docs have an incorrect example. We will update that."

Changes

Before:

await db.insert(users).values({ name: "Dan" }).output();
await db.insert(users).values({ name: "Partial Dan" }).output({ insertedId: users.id });

After:

await db.insert(users).output().values({ name: "Dan" });
await db.insert(users).output({ insertedId: users.id }).values({ name: "Partial Dan" });

Also corrected the description which incorrectly said "PostgreSQL and SQLite" instead of "MSSQL".

Per MSSQL SQL syntax, OUTPUT clause comes before VALUES.
The correct Drizzle API is:
  db.insert(users).output().values({ name: 'Dan' })
not .values(...).output().

Fixes drizzle-team/drizzle-orm#5472
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.

[BUG]: MSSQL insert().values().output() is not a function

1 participant