P
Prisma2mo ago
Shahor

Failing to write raw query

Hi, I have a (working) raw query that I want to run with prisma but I can't find how to do so and I'm a bit confused as to how I can approach this. For simplicity's sake, my query can be reduced to:
SELECT unnest(array ['foo', 'bar'])
SELECT unnest(array ['foo', 'bar'])
Assuming 'foo' and 'bar' are parameters like:
const values = ['foo', 'bar']
const values = ['foo', 'bar']
Here's what I tried initially:
const rows = await prisma.queryRaw<{ value: string }[]>`
SELECT unnest(array [${values}]
const rows = await prisma.queryRaw<{ value: string }[]>`
SELECT unnest(array [${values}]
But to no success. I've tried a few variations of this but can't for the life of me have it work. Does anyone know how to do this?
Solution:
Raw queries | Prisma Documentation
Learn how you can send raw SQL and MongoDB queries to your database using the raw() methods from the Prisma Client API.
Jump to solution
4 Replies
Shahor
Shahor2mo ago
Ok, found out about Prisma.join and ... wow is the documentation making simple things hard to find 😐
Solution
Shahor
Shahor2mo ago
Raw queries | Prisma Documentation
Learn how you can send raw SQL and MongoDB queries to your database using the raw() methods from the Prisma Client API.
jonfanz
jonfanz2mo ago
Thank you for the feedback. Where would you expect to find that documentation? How can we make it easier to discover?
Shahor
Shahor2mo ago
I'm not sure But it's kind of hard to spot as a very tiny paragraph in a wall of text Why does it have to be handled in a special way? Can't it be done by default? I would expect
queryRaw`select * from foo where bar IN (${someArrayOfValues})
queryRaw`select * from foo where bar IN (${someArrayOfValues})
To just understand what I'm trying to do. It seems to be the most likely case anyways, so maybe using helpers for the less common cases would be more "intuitive"