$queryRaw doesn't work with single quotes
See original GitHub issueDiscussed in https://github.com/prisma/prisma/discussions/9991
<div type='discussions-op-text'>Originally posted by bardiaheshmati October 28, 2021 i have a query that goes
select count(id), status, "createdAt"::date from "ProjectLog" where "projectId" = (select id from "Project" where slug = ${id}) and "createdAt" > current_date - interval '${interval} day' group by "createdAt"::date, status;
i’ve also tried user Prisma.sql
to pass the value inside the quotes but it keeps throwing error that it expected 1 argument but fount 2.
i did not have this issue with prisma 2.20.1
this issue is only happening on version 3.3.0
Query: select count(id) as count, status, "createdAt"::date from "ProjectLog" where "projectId" = (select id from "Project" where slug = $1) and "createdAt" > current_date - interval '$2 day' and key notnull group by "createdAt"::date, status
Param: ["main","30"]
PrismaClientKnownRequestError:
Invalid `prisma.queryRaw()` invocation:
Your raw query had an incorrect number of parameters. Expected: `1`, actual: `2`.
code: 'P1016',
clientVersion: '3.3.0',
meta: { expected: 1, actual: 2 }
}
any suggestions ? i’m not sure if this is a bug.
</div>Issue Analytics
- State:
- Created 2 years ago
- Reactions:2
- Comments:7 (5 by maintainers)
Top Results From Across the Web
prisma $queryRaw doesn't work with single quotes in the string
sql to pass the value inside the quotes but it keeps throwing error that it expected 1 argument but fount 2. i did...
Read more >Prisma $queryRaw cannot grab any tables added from migration
Hey there, I have a web app I've been working on, ... seems also wrapping 'Tournament' in double quotes fixed the issue, so...
Read more >Dealing with single Quote in SQL Query
Hi Guys. how do I deal with single Quote inside string in an SQL query? currently this type of query is failing with...
Read more >Raw database access (Reference) - Prisma
Type caveats when using raw SQL. When you type the results of $queryRaw , the raw data might not always match the suggested...
Read more >[Solved]-Need replace text with single quotes in SQL-postgresql
Coding example for the question Need replace text with single quotes in SQL-postgresql. ... prisma $queryRaw doesn't work with single quotes in the...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Hey folks,
@jschuur I can confirm this is a SQL prepared statement limitation. Your query parameter is interpreted as a text because it is inside single quotes. I see two ways you could make this work (without using
$queryRawUnsafe
):${"7 day"}
as query parameter"day"
static. eg 👇With that, I’m gonna close the issue as there’s nothing we can do about it.
Thanks for reporting! 🙏
Thanks, with this information we can take a deeper look @jschuur 👍