🌐
Prisma
prisma.io › home › raw queries › raw queries › raw queries › raw queries
Raw queries | Prisma Documentation
Prisma Client specifically uses SQL Template Tag, which exposes a number of helpers. For example, the following query uses join() to pass in a list of IDs:
Discussions

How to Join and Union in rawQuery
I tried to use join in the SQL query but I got this error · prisma.$queryRaw()` invocation: Raw query failed. More on github.com
🌐 github.com
2
1
August 8, 2023
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
SQL joins without relations/foreign keys/raw query
Problem I sometimes find myself wanting to join 2 tables that are related by a column, but don't have referential integrity. For example, let's say I have 2 tables, Transaction and SmartCon... More on github.com
🌐 github.com
11
May 27, 2022
using `queryRaw` with `sql` to do javascript functions?
Thank you for your understanding and ongoing support of the Prisma community! Beta Was this translation helpful? Give feedback. ... Sign up for free to join this conversation on GitHub. Already have an account? More on github.com
🌐 github.com
2
1
🌐
GitHub
github.com › prisma › prisma › discussions › 24838
Queryraw condition joining · prisma/prisma · Discussion #24838
July 23, 2024 - The conditions array is joined with AND using Prisma.join with a string separator ' AND '. The final query is constructed using Prisma.sql, ensuring that the SQL string and the parameters are correctly aligned.
Author   prisma
🌐
GitHub
github.com › prisma › prisma › discussions › 20563
How to Join and Union in rawQuery · prisma/prisma · Discussion #20563
August 8, 2023 - prisma.$queryRaw` SELECT id, amount, title, updatedAt, type, name AS category FROM ( SELECT e.id, e.amount, e.title, e.updatedAt, e.type, ec.name FROM "Expense" e INNER JOIN "CategoriesOnExpense" ce ON e.id = ce."expenseId" INNER JOIN "ExpenseCategory" ec ON ce."categoryId" = ec.id WHERE e."ownerId" = ${userId} AND e."year" = ${year} AND e."month" = ${month} UNION SELECT i.id, i.amount, i.title, i.updatedAt, i.type, ic.name FROM "Income" i INNER JOIN "CategoriesOnIncome" ci ON i.id = ci."incomeId" INNER JOIN "IncomeCategory" ic ON ci."categoryId" = ic.id WHERE i."ownerId" = ${userId} AND i."year" = ${year} AND i."month" = ${month} ) AS result ORDER BY result."updatedAt" DESC; `;
Author   prisma
🌐
GitHub
github.com › prisma › prisma › discussions › 17158
Joined Relations with $queryRaw · prisma/prisma · Discussion #17158
The $queryRaw method will return the data as it is retrieved from the database, which means that if you perform a join in your raw SQL query, the result will be a flat structure with columns from both tables.
Author   prisma
🌐
MCP Servers
mcpservers.org › home › agent skills library › prisma-client-api-raw-queries
prisma-client-api-raw-queries | Agent Skills Library
import { Prisma } from '../generated/client' const column = 'email' const users = await prisma.$queryRaw` SELECT ${Prisma.raw(column)} FROM "User" ` ... import { Prisma } from '../generated/client' const email = '[email protected]' const query = Prisma.sql`SELECT * FROM "User" WHERE email = ${email}` const users = await prisma.$queryRaw(query) import { Prisma } from '../generated/client' const conditions = [ Prisma.sql`role = ${'ADMIN'}`, Prisma.sql`verified = ${true}` ] const users = await prisma.$queryRaw` SELECT * FROM "User" WHERE ${Prisma.join(conditions, ' AND ')} `
🌐
Prisma
prisma.io › home › relation queries › relation queries › relation queries › relation queries
Relation queries (Concepts) | Prisma Documentation
The join strategy (default) will be more effective in most scenarios. On PostgreSQL, it uses a combination of LATERAL JOINs and JSON aggregation to reduce redundancy in result sets and delegate the work of transforming the query results into the expected JSON structures on the database server.
Find elsewhere
🌐
Atomic Spin
spin.atomicobject.com › prisma-queryraw
Building an SQL Query from Variables with prisma.$queryRaw
July 19, 2024 - Using prisma.$queryRaw, I was able to write a basic query that returned the data I needed. However, I also needed the query to filter and order the data.
🌐
GitHub
github.com › prisma › prisma › issues › 13517
SQL joins without relations/foreign keys/raw query · Issue #13517 · prisma/prisma
May 27, 2022 - Problem I sometimes find myself wanting to join 2 tables that are related by a column, but don't have referential integrity. For example, let's say I have 2 tables, Transaction and SmartCon...
Author   prisma
🌐
Prisma
prisma.io › blog › prisma-orm-now-lets-you-choose-the-best-join-strategy-preview
Choosing the Best Join Strategy in Prisma ORM: join vs query
February 21, 2024 - Prisma ORM loads relations with database-level joins (a single SQL query with JSON aggregation) or application-level joins (one query per table). Learn how both work and when to use which.
🌐
New Releases
newreleases.io › project › github › prisma › prisma › release › 2.0.0-beta.6
prisma/prisma 2.0.0-beta.6 on GitHub
May 26, 2020 - In order to construct raw SQL queries programmatically, Prisma Client now exposes a few helper functions: import { sql, empty, join, raw, PrismaClient } from '@prisma/client' const prisma = new PrismaClient() const rawQueryTemplateFromSqlTemplate ...
🌐
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
Similar to raw queries in relational databases, these methods are not type-safe and require manual handling of the query results. ... Learn how you can send raw SQL and MongoDB queries to your database using the raw() methods from the Prisma Client API
🌐
DEV Community
dev.to › this-is-learning › its-prisma-time-execute-your-own-queries-4olp
It's Prisma Time - Execute your own queries - DEV Community
January 28, 2022 - This method uses the Tagged Template and it prevents attack by SQL-injection too. The result of this method is always an array and the type of this array depends on the result of your query. To explain better this concept let me give an example. const result: Post[] = await prisma.$queryRaw<Post[]>` SELECT p.id, p.title, p.content, p.published, p.createAt, p.updatedAt FROM posts p WHERE p.published = ${true} ORDER BY p.createAt DESC`; result.forEach(post => { const { id, title, content, createAt, published, updatedAt } = post; console.log({ id, title, content, createAt, published, updatedAt, }); });
🌐
Prisma
prisma.io › dataguide › types › relational › what-are-joins-in-sql
What are JOINs in SQL? | Prisma's Data Guide
Here is an example SQL schema demonstrating a one-to-many relation between users and posts tables: ... CONSTRAINT fk_posts_author_id FOREIGN KEY (author_id) REFERENCES users (id) ON DELETE RESTRICT ON UPDATE CASCADE ... This means that one user can have multiple posts, but each post is linked to only one user. When dealing with one-to-many relations, traditional JOINs can lead to duplicated data. Consider the following query:
🌐
DEV Community
dev.to › aws-builders › i-ditched-prisma-for-raw-sql-and-my-queries-got-10x-faster-4gen
I Ditched Prisma for Raw SQL (And My Queries Got 10x Faster) - DEV Community
April 6, 2026 - Prisma executes this as 4 separate queries: one for projects, one for members, one for apiKeys, one for the count. Then it assembles the result in JavaScript. The raw equivalent is one query.
🌐
Stack Overflow
stackoverflow.com › questions › 74274673 › raw-query-in-prisma-query-console
Raw query in Prisma Query Console - Stack Overflow
The workaround is to use $queryRawUnsafe. The syntax is · await prisma.$queryRawUnsafe('SELECT * FROM "public"."User"')