New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
.raw doesn't return data if query doesn't start with SELECT statement #2208
Comments
You don't need to add single quotes to the parameter. Raw uses prepared statements under the hood so every variable you are using in the query is replaced by a prepared statement variable. If you add quotes, postgres will treat them as a string and when we try to pass the variables to the prepared statement, the query will be rejected by the PostgreSQL instance. The following query should work for your use case: const data = await prisma.raw`
WITH RECURSIVE descendants AS (
SELECT *
FROM "Task"
WHERE id = ${id}
UNION ALL
SELECT t.*
FROM "Task" t
JOIN descendants ON t."parentId" = descendants.id
)
SELECT * FROM descendants;
`; |
Oh in that case |
Looks like a bug to me now, we need to investigate this further. Malformed data might be coming from the driver that we are using. I can confirm this behaviour though. |
Yep. I knew this will happen at some point. So currently we decide is the query a Solution, implement two different calls:
This would follow how every other SQL client does the differentiation between |
Ran into this as well expecting to get data back when doing something like this:
The |
@TLadd I just got exactly the same problem as yours. Want to get the id of the newly inserted record, but had to write another |
+1 |
I'm having the same issue of the number of rows being returning instead of the actual row data.
The query works correctly when run directly on the db. |
Update:
|
I'm using the Prisma Beta2 with Postgres and
prisma.raw
and am getting a panic error when trying to do a recursive query.I have the following schema
I need to get all descendants of a given node referenced via it's
id
. The following sql gets me the results I need. It works perfectly fine in postgres.However, when I plug it into
prisma.raw
I get theError: PANIC: expected 0 parameters but got 1
Here's my error logs:
Am I also correct in assuming this query can't be done with graphql?
Edit: The same query is working fine with https://node-postgres.com/
The text was updated successfully, but these errors were encountered: