Use unsupported SQL features
A typed Prisma query cannot express a required SQL feature.
Prisma · Function
Prisma.raw constructs raw SQL for use with Prisma Client raw-query methods. It is an unsafe escape hatch: manually assembled queries require database-specific parameter markers and careful handling of all dynamic input.
Prisma.raw constructs a raw SQL fragment or query string that can be passed to Prisma Client raw-query methods. Because Prisma cannot add parameter markers or safely interpolate values into a string built this way, callers must supply the database-specific markers and avoid incorporating untrusted input.
Prisma.raw(query)| Name | Type | Description |
|---|---|---|
query | string | The raw SQL string or fragment to construct. The documentation page does not specify a separately documented parameter type. |
A raw SQL value suitable for use with Prisma raw-query methods; the fetched documentation does not state a separate return type.
Prisma.raw as an unsafe construction escape hatch, not as automatic protection against SQL injection.Prisma.raw can make a raw query vulnerable to SQL injection.Prisma.raw is potentially dangerous and requires care.const query = Prisma.raw('SELECT * FROM "User" WHERE email = $1');
const users = await prisma.$queryRaw(query);Build a complete raw SQL string only when its contents and parameter markers are controlled; otherwise use the safer tagged-template form.
A typed Prisma query cannot express a required SQL feature.
A raw statement must be assembled as a single string using known, trusted SQL text.
Prisma.raw used for?Prisma.raw is an escape hatch for constructing raw SQL that can be supplied to Prisma raw-query methods. It is useful when a query cannot be expressed through Prisma's typed API, but it does not provide the same safety as a tagged template when misused.
Follow-up: How would you safely include a user-provided email? Use $queryRaw with a tagged template and interpolate the value as a parameter rather than concatenating it into a Prisma.raw string.
Prisma.raw?A string assembled with Prisma.raw must use the parameter-marker syntax required by the target database. Prisma cannot infer or insert those markers for a manually built raw string.
Follow-up: Why is this different from a tagged template? The tagged-template API can construct parameters for the database, while a manually assembled raw string leaves marker construction to the caller.
Prisma.raw?The function can be dangerous when dynamic or untrusted input is incorporated into the resulting SQL. The documentation specifically warns that misuse can make raw-query methods vulnerable to SQL injection.
Follow-up: What is the safer default? Prefer Prisma's typed query API, or use parameterized $queryRaw tagged templates when raw SQL is necessary.
$queryRaw$executeRaw$queryRawUnsafe$executeRawUnsafe