fix(docs): refer wrong raw query methods in ORM > Using Raw SQL > TypeSQL#7867
fix(docs): refer wrong raw query methods in ORM > Using Raw SQL > TypeSQL#7867Hephaest wants to merge 1 commit intoprisma:mainfrom
Conversation
|
@Hephaest is attempting to deploy a commit to the Prisma Team on Vercel. A member of the Team first needs to authorize it. |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yaml Review profile: CHILL Plan: Pro Run ID: 📒 Files selected for processing (2)
WalkthroughTwo versions of Prisma TypedSQL documentation are updated to recommend ChangesDocumentation Guidance Update
Estimated code review effort🎯 1 (Trivial) | ⏱️ ~3 minutes 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Tip 💬 Introducing Slack Agent: The best way for teams to turn conversations into code.Slack Agent is built on CodeRabbit's deep understanding of your code, so your team can collaborate across the entire SDLC without losing context.
Built for teams:
One agent for your entire SDLC. Right inside Slack. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
aidankmcalister
left a comment
There was a problem hiding this comment.
Good catch — the existing text is indeed wrong, and this fix is technically correct.
Why $queryRawUnsafe / $executeRawUnsafe is the right choice here:
$queryRaw and $executeRaw are implemented as tagged template literals. This design is intentional for SQL injection safety — Prisma converts interpolated values into parameterized query arguments. However, this mechanism only works for data values (e.g. WHERE email = ${email}). Template variables cannot be used for identifiers like column names, table names, or SQL keywords.
From our own docs on $queryRaw considerations:
"Variables cannot be used for identifiers such as column names, table names or database names, or for SQL keywords."
This means code like prisma.$queryRaw\SELECT ${columns} FROM Users`` would not work as intended for dynamic column selection — the column list would be parameterized as a bound value, not interpolated as SQL identifiers, causing a query error.
$queryRawUnsafe (and $executeRawUnsafe) accept a plain string and perform direct string interpolation, which is the only way to dynamically construct column/table identifiers at runtime. The example code in the docs is correct; only the preceding text was wrong.
The PR correctly updates the text in both v6 (content/docs/orm/v6/...) and v7 (content/docs/orm/...) docs to match the example.
Approved — thanks for the thorough investigation and the screenshots as proof!
Summary
In Dynamic SQL Queries with Dynamic Columns section, the doc clearly mentioned:
It looks counterintuitive to me, so I do check on my own. The search results confirmed my assumptions: the doc might refer to the wrong methods.
Proofs:
Under

$queryRawconsiderations>Under

$executeRawconsiderations>Summary by CodeRabbit