🌐
Prisma
prisma.io › home › raw queries › raw queries › raw queries › raw queries
Raw queries | Prisma Documentation
Prisma maps any database values returned by $queryRaw and $queryRawUnsafeto their corresponding JavaScript types. This behavior is the same as for regular Prisma query methods like findMany(). As an example, take a raw query that selects columns with BigInt, Bytes, Decimal and Date types from a table:
🌐
Reddit
reddit.com › r/nextjs › how often do you write a raw query using prisma
r/nextjs on Reddit: How often do you write a raw query using Prisma
July 8, 2024 -

I want to use an ORM so that it can handle optimization and provide nice abstractions

So I started learning Prisma, but every time I want to do something just little involved I end up needing to write a raw query for it.

for example, how can I write this without using the raw query:

  const rawResults = await db.$queryRaw`
    select
      age,
      round(avg(todep), 2) as avg_phq9,
      round(avg(tosc), 2) as avg_scs,
      round(avg(toas), 2) as avg_asiss,
      round(avg(todep + tosc + toas), 2) as total_score

    from students
    where inter_dom = 'Inter'
    group by age
    order by total_score desc
  `;

I don't want to waste time learning other stuff, I just wanna know is that normal for you guys to use raw queries so often with Prisma.

does Drizzle solve this problem?

I'm aware of the extends and query extensions... if $extends is capable of doing aggregate and all that could be nice.

Prisma ORM in NodeJS with TypeScript May 20, 2024
r/node
2y ago
Is Prisma limited? Jun 10, 2025
r/node
last yr.
New to node. Does prisma suck? Oct 27, 2024
r/node
last yr.
dont use or start with prisma Sep 16, 2025
r/nextjs
10mo ago
More results from reddit.com
Discussions

Raw query in Prisma Query Console - Stack Overflow
I'm trying to run a raw query in the Prisma Query Console of the Data Platform. More on stackoverflow.com
🌐 stackoverflow.com
Queryraw condition joining
Question I need to use a procedure and then filter on this from a sqlserver database. I am having some issues constructing a query that is dynamic and safe. Prisma.join is only for joining values, ... More on github.com
🌐 github.com
2
2
July 23, 2024
Type error in `IN` clause in postgreSQL using `$queryRaw` when upgrading to v4
Bug description There seems to be a regression regarding IN clauses in postgreSQL in prisma v4. The issue happened on postgresql and the behaviour changed somewhere between prisma 3.15.2 and 4.2.1. For a given table of this structure: CR... More on github.com
🌐 github.com
21
August 24, 2022
postgresql - Prisma $queryRaw with variable length parameter list - Stack Overflow
But when you use uuid type, Prisma's join function formats the parameters adding double apostrophe. So you can take error like 'type mismatch' in PostreSQL. Alternatively, you can use native Array.join function to build a sql string and send it to Prisma raw query function using Prisma.raw function. More on stackoverflow.com
🌐 stackoverflow.com
🌐
Medium
medium.com › javarevisited › prisma-vs-raw-sql-i-measured-query-performance-for-30-days-b97c0ed5aa7d
Prisma vs Raw SQL: I Measured Query Performance for 30 Days. | by Devrim Ozcay |Production System Engineer | Founder | Javarevisited | Medium
January 12, 2026 - If you’re building production systems and want a solid foundation to start from, I packaged up the patterns that actually worked: 👉 Next.js SaaS Starter Template — includes the Prisma + raw SQL setup I’m using now. Truth 1: Prisma is slower. Deal with it. For complex queries, raw SQL will always be faster.
🌐
Atomic Spin
spin.atomicobject.com › prisma-queryraw
Building an SQL Query from Variables with prisma.$queryRaw
July 19, 2024 - On a recent project, I needed to break out Prisma’s query builder to write a Postgres-specific query. Using prisma.$queryRaw, I was able to write a basic query that returned the data I needed.
🌐
Nodejs-security
nodejs-security.com › blog › prisma-raw-query-sql-injection
Prisma Raw Query Leads to SQL Injection? Yes and No
While this looks like a regular string interpolation, it is actually a special syntax that allows you to define a function (in this case $queryRaw is the function) that handles the data in the placeholder variable.
🌐
DEV Community
dev.to › jquagliatini › improving-prisma-raw-query-typing-nhd
Improving Prisma raw queries typing. - DEV Community
March 1, 2023 - import { Prisma } from '@prisma/client'; export const P = Object.fromEntries( Object.values(Prisma.ModelName).map((modelName) => { const model = Prisma.dmmf.datamodel.models.find( ({ name }) => name === modelName ) as Prisma.DMMF.Model; return [ modelName, { tableName: Prisma.raw(model.dbName ?? model.name), fields: Object.fromEntries( Object.values(Prisma[`${modelName}ScalarFieldEnum`]).map( (field) => { const dmmfField = model.fields .filter( ({ kind }) => !["object", "unsupported"].includes(kind) ) .find(({ name }) => name === field) as Prisma.DMMF.Field; return [field, Prisma.raw(dmmfField
🌐
Prisma
prisma.io › blog › announcing-typedsql-make-your-raw-sql-queries-type-safe-with-prisma-orm
Announcing TypedSQL: Make your raw SQL queries type-safe with Prisma ORM
August 27, 2024 - With today’s Prisma ORM v5.19.0 release, we are thrilled to announce TypedSQL: The best way to write complex and highly performant queries. TypedSQL is just SQL, but better. It’s fully type-safe, provides auto-completion, and gives you a fantastic DX whenever you need to craft raw SQL queries.
Find elsewhere
🌐
Stack Overflow
stackoverflow.com › questions › 74274673 › raw-query-in-prisma-query-console
Raw query in Prisma Query Console - Stack Overflow
Here is the answer from Prisma support: The format of $queryRaw without parenthesis isn't supported yet, due to which the execution is disabled. The error that is returned suggests defining variables and passing them in $queryRaw in tagged literal format, as of now defining variables in Query Console isn't supported either.
🌐
GitHub
github.com › prisma › prisma › discussions › 24838
Queryraw condition joining · prisma/prisma · Discussion #24838
July 23, 2024 - const conditions = []; const params = []; if (bookingCount !== undefined) { conditions.push(Prisma.sql`bookingCount > ${bookingCount}`); } if (Array.isArray(zipCodeLike) && zipCodeLike.length > 0) { const zipConditions = zipCodeLike.map(zip => Prisma.sql`recentZIPCode LIKE ${zip}`); conditions.push(Prisma.sql`(${Prisma.join(zipConditions, ' OR ')})`); } // Combine all conditions into a single WHERE clause let whereClause = Prisma.empty; if (conditions.length > 0) { whereClause = Prisma.sql`WHERE ${Prisma.join(conditions, ' AND ')}`; } // Construct the final query using Prisma.sql const query = Prisma.sql`SELECT * FROM USER ${whereClause}`;
Author   prisma
🌐
Prisma
prisma.io › home › relation queries › relation queries › relation queries › relation queries
Relation queries (Concepts) | Prisma Documentation
Prisma Client supports two load strategies for relations: join (default): Uses a database-level LATERAL JOIN (PostgreSQL) or correlated subqueries (MySQL) and fetches all data with a single query to the database.
🌐
GitHub
github.com › prisma › prisma › issues › 14978
Type error in `IN` clause in postgreSQL using `$queryRaw` when upgrading to v4 · Issue #14978 · prisma/prisma
August 24, 2022 - const rows = await this.prismaClient.$queryRaw< { id: string }[] >(Prisma.sql` SELECT id FROM repro WHERE id IN (${Prisma.join(ids)}); `)
Author   prisma
🌐
Prisma
prisma.io
Prisma | Agent Infrastructure for TypeScript
Prisma ORM gives TypeScript developers a schema-first workflow with a generated client, autocomplete, and compile-time guarantees.
🌐
MDPI
mdpi.com › 2079-9284 › 12 › 2 › 51
Mechanistic Insights into Pigmented Rice Bran in Mitigating UV-Induced Oxidative Stress, Inflammation, and Pigmentation
March 14, 2025 - Papers published prior to 15 November 2024 were retrieved in accordance with the guidelines of the Preferred Reporting Items for Systematic Reviews and Meta-Analyses (PRISMA), which is an evidence-based minimum set of items for reporting in systematic reviews and meta-analyses [27]. The search query was performed in the WOS core collection based on the keywords pigmented rice, constituent analysis, and molecular mechanisms.
🌐
Prisma
prisma.io › home › prisma cli reference › prisma cli reference › prisma cli reference
Prisma CLI reference | Prisma Documentation
Next, run the prisma dev command to interact with your local Prisma Postgres instance (e.g. to run migrations or execute queries).
🌐
Prisma
docs.prisma.io › home › prisma orm
What is Prisma ORM? (Overview) | Prisma Documentation
Raw SQL gives full control but is error-prone and lacks type safety. Traditional ORMs improve productivity but abstract too much, leading to the object-relational impedance mismatch and performance pitfalls like the n+1 problem. Prisma takes a different approach: Type-safe queries validated at compile time with full autocompletion ·
🌐
GitHub
github.com › prisma › prisma › issues › 8270
Enable raw query support in MongoDB · Issue #8270 · prisma/prisma
July 14, 2021 - We offer the $queryRaw API for SQL users. I think we could extend that interface for MongoDB. The generated API would need to change slightly since MongoDB works with JSON objects, not strings. Perhaps something like: - prisma.$queryRaw(`...`) + prisma.$queryRaw({ ...
Author   prisma
🌐
GitHub
github.com › prisma › prisma › issues › 2208
.raw doesn't return data if query doesn't start with SELECT statement · Issue #2208 · prisma/prisma
April 16, 2020 - bug/2-confirmedBug has been reproduced and confirmed.Bug has been reproduced and confirmed.kind/bugA reported bug.A reported bug.tech/enginesIssue for tech Engines.Issue for tech Engines.topic: raw$queryRaw(Unsafe) and $executeRaw(Unsafe): https://www.prisma.io/docs/concepts/components/prisma-cli$queryRaw(Unsafe) and $executeRaw(Unsafe): https://www.prisma.io/docs/concepts/components/prisma-cli
Author   prisma
🌐
Prisma
prisma.io › home › write your own sql › write your own sql › write your own sql
Write Your Own SQL in Prisma Client | Prisma Documentation
TypedSQL is a new feature of Prisma ORM that allows you to write your queries in .sql files while still enjoying the great developer experience of Prisma Client. You can write the code you're comfortable with and benefit from fully-typed inputs and outputs. ... By using TypedSQL, you can write efficient, type-safe database queries without sacrificing the power and flexibility of raw SQL.
🌐
GitHub
github.com › prisma › prisma › issues › 26545
Type inference in raw queries is broken for arrays containing single null element · Issue #26545 · prisma/prisma
March 7, 2025 - Type inference in raw queries is broken for arrays containing a single null element, even though the sql contains an explicit type cast like ${data}::uuid[] where data = [null]. I've observed this to occur on uuids and timestamptzs but other types also most likely affected too. 🔹 Minor: Unexpected behavior, but does not block development · import { PrismaClient } from "@prisma/client"; const client = new PrismaClient(); await client.$queryRaw`SELECT ${[null]}::timestamptz[];`; await client.$queryRaw`SELECT ${[null]}::uuid[];`;
Author   prisma