【发布时间】:2022-04-06 03:12:56
【问题描述】:
我有一个查询
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;
我也尝试过用户 Prisma.sql 传递引号内的值,但它一直抛出错误,它期望 1 个参数但找到 2 个。
prisma 2.20.1 没有这个问题
这个问题只发生在版本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 }
}
有什么建议吗? 我不确定这是否是一个错误。
【问题讨论】:
-
问题解决了吗?
-
不,还有这个问题
-
错误是因为查询不期望那里有变量。可能您尝试使用字符串插值,并用变量 prisma.io/docs/concepts/components/prisma-client/… 替换查询块,看看这个链接。可能有帮助
标签: postgresql orm prisma pg